** The following commands create variables from each ANES TS study to merge with ANES cumulative data file.
** The identification of these variables is described in SI C
** first, download and create the Stata version of each time series study from electionstudies.org and save in a common working directory
** then, after confirming each TS study has the same file name as below, run the following code within the working directory

** 1952 - Complete- religid and religserv only

set more off
use NES1952.dta, clear
gen year = 1952 

gen pastvote = V520179
recode pastvote 10=1 20=2 30/40=3 50=0 60=. 70=1 80=2 91=. 98=. 99=.
gen currentvote = V520178
recode currentvote  10=1 20=2 30=3 40=. 41=. 42=. 50=0 60=0 70=0 71=0 72=0 99=.

gen nopre=0
replace nopre = 1 if V520003==3
replace nopre = 1 if V520003==4

gen undecided = 0 if nopre==0
replace undecided = 1 if V520080 == 8
replace undecided = . if V520080 == 9
replace undecided= . if V520080==0
replace undecided= . if V520080==6
replace undecided = 0 if V520086>0 & V520086<=5
replace undecided = . if V520086 == 6
replace undecided = 0 if V520086 == 7
replace undecided = 1 if V520086 == 8
replace undecided = . if V520086 == 9

gen weight = 1
set type double
gen id = V520002+19520000

gen issuevote=.

gen religid =  V520158
replace religid = . if  V520158 == 9 
replace religid = 4 if  V520158 == 3
replace religid = 9 if  V520158 == 0

gen religserv = V520159
replace religserv = . if  V520159 == 9
replace religserv = 4 if  V520159 == 3
replace religserv = 5 if  V520159 == 4

gen religpray = .
gen religimp = .
gen religfine = .

keep year id weight pastvote currentvote undecided issuevote religid religserv religpray  religimp religfine
order year id weight pastvote currentvote undecided issuevote religid religserv religpray  religimp religfine
saveold "Newmerge1952.dta", replace


** 1956- Complete- religid & religserv

use NES1956.dta, clear
gen year=1956

gen pastvote = V560096
recode pastvote 10=1 20=2 30=3 40=0 50=. 60=. 91/99=.
replace pastvote = 0 if V560093==7
replace pastvote = 0 if V560093==5
gen currentvote = V560203
recode currentvote  11=1 12=2 13=3 14=. 18=. 19=. 21/30=0

gen nopre=0
replace nopre = 1 if V560009==0

** Issue placement, 5 issues with fewest DK+No Opinions
* build schools 18 + 147 = 165
* guarantee job: 151+20 = 171
* half-way: 10 + 177 = 187
* school int: 180+22 = 202
* hospital care 18+186 = 204

** First measure whether resp. had opinion and saw difference b/n parties/candidates on 5 issues
* 1. Help build schools 
gen haveopinion11 = 0 if V560053!=9 
replace haveopinion11 = 1 if V560053>=1 & V560053<=5
gen seediff11 = 0 if V560053!=9 & V560055!=9
replace seediff11 = 1 if V560055==1
replace seediff11 = 1 if V560055==5
* 2. See to it Job 
gen haveopinion12 = 0 if V560032!=9 
replace haveopinion12 = 1 if V560032>=1 & V560032<=5
gen seediff12 = 0 if V560032!=9 & V560034!=9
replace seediff12 = 1 if V560034==1
replace seediff12 = 1 if V560034==5
* 3. Halfway with countries
gen haveopinion13 = 0 if V560065!=9 
replace haveopinion13 = 1 if V560065>=1 & V560065<=5
gen seediff13 = 0 if V560065!=9 & V560067!=9
replace seediff13 = 1 if V560067==1
replace seediff13 = 1 if V560067==5
* 4. School integration
gen haveopinion14 = 0 if V560074!=9 
replace haveopinion14 = 1 if V560074>=1 & V560074<=5
gen seediff14 = 0 if V560074!=9 & V560076!=9
replace seediff14 = 1 if V560076==1
replace seediff14 = 1 if V560076==5
* 5. Hospital care low cost
gen haveopinion15 = 0 if V560038!=9 
replace haveopinion15 = 1 if V560038>=1 & V560038<=5
gen seediff15 = 0 if V560038!=9 & V560040!=9
replace seediff15 = 1 if V560040==1
replace seediff15 = 1 if V560040==5

** Now combine by scoring how many issues respondent met issue voting criteria
gen issuevote1 = 0 if haveopinion11+seediff11!=2
replace issuevote1 = 1 if haveopinion11+seediff11==2
replace issuevote1 = . if haveopinion11==.
gen issuevote2 = 0 if haveopinion12+seediff12!=2
replace issuevote2 = 1 if haveopinion12+seediff12==2
replace issuevote2 = . if haveopinion12==.
gen issuevote3 = 0 if haveopinion13+seediff13!=2
replace issuevote3 = 1 if haveopinion13+seediff13==2
replace issuevote3 = . if haveopinion13==.    
gen issuevote4 = 0 if haveopinion14+seediff14!=2
replace issuevote4 = 1 if haveopinion14+seediff14==2
replace issuevote4 = . if haveopinion14==.
gen issuevote5 = 0 if haveopinion15+seediff15!=2
replace issuevote5 = 1 if haveopinion15+seediff15==2
replace issuevote5 = . if haveopinion15==.

** now average across 5 items, or 4 if 1 is missing
gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

gen undecided = 0 if nopre==0
replace undecided = . if V560100 == 0
replace undecided = 1 if V560100 == 3
replace undecided = . if V560100 == 6
replace undecided = 1 if V560100 == 8
replace undecided = . if V560100 == 9

replace undecided = 0 if V560104>0 & V560104<=2
replace undecided = 1 if V560104 == 3
replace undecided = 0 if V560104>3 & V560104<=5
replace undecided = . if V560104== 6
replace undecided = 0 if V560104== 7
replace undecided = 1 if V560104 == 8
replace undecided = . if V560104 == 9

gen weight = 1
set type double
gen id = V560002+19560000

gen religid =  V560132
replace religid = . if  V560132 == 9 
replace religid = 4 if  V560132 == 3
replace religid = 9 if  V560132 == 0

gen religserv = V560133
replace religserv = . if  V560133 == 9

gen religpray = .
gen religimp = .
gen religfine = .

keep year id weight pastvote currentvote undecided issuevote haveopinion11 seediff11 haveopinion12 seediff12 haveopinion13 seediff13 haveopinion14 seediff14 haveopinion15 seediff15 religid religserv religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote haveopinion11 seediff11 haveopinion12 seediff12 haveopinion13 seediff13 haveopinion14 seediff14 haveopinion15 seediff15 religid religserv religpray religimp religfine
saveold "Newmerge1956.dta", replace


** 1960 - Complete- religid & religserv

use NES1960.dta, clear
gen year=1960
gen weight = V600003
sum weight
replace weight = weight/(r(sum)/r(N))

gen pastvote = V600097
recode pastvote 0=. 4=0 5=. 6=. 7/9=.
replace pastvote=0 if V600095==5 
replace pastvote=0 if V600095==7

gen currentvote = V600201
recode currentvote  10=1 20=2 30=3 40/60=. 70/99=0

gen nopre=0
replace nopre = 1 if V600016==2

gen undecided = 0 if nopre==0
replace undecided = . if V600101 == 0
replace undecided = 1 if V600101 == 3
replace undecided = . if V600101 == 7
replace undecided = 1 if V600101 == 8
replace undecided = . if V600101 == 9
replace undecided = 0 if V600104>0 & V600104<=2
replace undecided = 1 if V600104 == 3
replace undecided = 0 if V600104>3 & V600104<=6
replace undecided = 0 if V600104== 7
replace undecided = 1 if V600104 == 8
replace undecided = . if V600104 == 9

* issuevote
*60
* med care = 80 + 17 
* employment = 94 + 17
* isolationism = 99 + 12 
* education = 94+19
* equality for negroes = 104+22

* undeveloped nations = 122+17
* integrate schools = 119 + 28
* communism = 147 + 32
* hsg & pwr = 235+15	

* 1. Aid Education 
gen haveopinion21 = 0 if V600058!=9
replace haveopinion21 = 1 if V600058>=1 & V600058<=5
gen seediff21 = 0 if V600058!=9 & V600059!=9
replace seediff21 = 1 if V600059==1
replace seediff21 = 1 if V600059==5
* 2. Govt Guarantee emplymnt 
gen haveopinion22 = 0 if V600054!=9
replace haveopinion22 = 1 if V600054>=1 & V600054<=5
gen seediff22 = 0 if V600054!=9 & V600055!=9
replace seediff22 = 1 if V600055==1
replace seediff22 = 1 if V600055==5
* 3. 632 Subsidize medical care * 181
gen haveopinion23 = 0 if V600066!=9
replace haveopinion23 = 1 if V600066>=1 & V600066<=5
gen seediff23 = 0 if V600067!=9 & V600068!=9
replace seediff23 = 1 if V600068==1
replace seediff23 = 1 if V600068==5
* 4. 622 Isolationism * 195
gen haveopinion24 = 0 if V600056!=9
replace haveopinion24 = 1 if V600056>=1 & V600056<=5
gen seediff24 = 0 if V600056!=9 & V600057!=9
replace seediff24 = 1 if V600057==1
replace seediff24 = 1 if V600057==5
* 5. 628 Help Blacks * 218
gen haveopinion25 = 0 if V600062!=9
replace haveopinion25 = 1 if V600062>=1 & V600062<=5
gen seediff25 = 0 if V600062!=9 & V600063!=9
replace seediff25 = 1 if V600063==1
replace seediff25 = 1 if V600063==5

gen issuevote1 = 0 if haveopinion21+seediff21!=2
replace issuevote1 = 1 if haveopinion21+seediff21==2
replace issuevote1 = . if haveopinion21==.
gen issuevote2 = 0 if haveopinion22+seediff22!=2
replace issuevote2 = 1 if haveopinion22+seediff22==2
replace issuevote2 = . if haveopinion22==.
gen issuevote3 = 0 if haveopinion23+seediff23!=2
replace issuevote3 = 1 if haveopinion23+seediff23==2
replace issuevote3 = . if haveopinion23==.    
gen issuevote4 = 0 if haveopinion24+seediff24!=2
replace issuevote4 = 1 if haveopinion24+seediff24==2
replace issuevote4 = . if haveopinion24==.
gen issuevote5 = 0 if haveopinion25+seediff25!=2
replace issuevote5 = 1 if haveopinion25+seediff25==2
replace issuevote5 = . if haveopinion25==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

set type double
gen id = V600002+19600000

gen religid = .
replace religid = 1 if  V600252 >= 100 &  V600252 <= 155 
replace religid = 2 if  V600252 == 200 
replace religid = 3 if  V600252 >= 700 &  V600252 <= 719 
replace religid = 4 if  V600252 == 300 
replace religid = 7 if  V600252 == 721
replace religid = 7 if  V600252 >= 729 &  V600252 <=  790 
replace religid = 8 if  V600252 == 728 
replace religid = 9 if  V600252 == 0 
replace religid = . if  V600252 >= 998 & V600252 <=  999 

gen religfine = .
replace religfine = 14 if V600252 == 100
replace religfine = 14 if V600252 == 101
replace religfine = 12 if V600252 == 102
replace religfine = 14 if V600252 == 109
replace religfine = 11 if V600252 == 110 
replace religfine = 11 if V600252 == 111
replace religfine = 11 if V600252 == 112
replace religfine = 12 if V600252 == 113 
replace religfine = 12 if V600252 == 114 
replace religfine = 11 if V600252 == 115
replace religfine = 11 if V600252 == 116
replace religfine = 11 if V600252 == 120
replace religfine = 13 if V600252 == 121
replace religfine = 12 if V600252 == 122
replace religfine = 12 if V600252 == 123
replace religfine = 11 if V600252 == 124
replace religfine = 14 if V600252 == 125
replace religfine = 12 if V600252 == 130
replace religfine = 12 if V600252 == 131
replace religfine = 12 if V600252 == 132
replace religfine = 12 if V600252 == 133
replace religfine = 12 if V600252 == 134
replace religfine = 12 if V600252 == 135
replace religfine = 12 if V600252 == 136
replace religfine = 14 if V600252 == 137
replace religfine = 12 if V600252 == 138
replace religfine = 12 if V600252 == 139
replace religfine = 12 if V600252 == 140
replace religfine = 12 if V600252 == 149
replace religfine = 14 if V600252 == 150
replace religfine = 14 if V600252 == 151
replace religfine = 14 if V600252 == 152
replace religfine = 14 if V600252 == 153
replace religfine = 14 if V600252 == 154
replace religfine = 14 if V600252 == 155
replace religfine = 14 if V600252 == 156
replace religfine = 2 if V600252 == 200
replace religfine = 4 if V600252 == 300
replace religfine = 3 if V600252 >= 700 & V600252 <= 719
replace religfine = 7 if V600252 == 721
replace religfine = 8 if V600252 == 728
replace religfine = 7 if V600252 == 729
replace religfine = 7 if V600252 == 790
replace religfine = 9 if V600252 == 998
replace religfine = 9 if V600252 == 0
replace religfine = . if V600252 == 999

gen religserv = V600253
replace religserv = . if  V600253 == 9
replace religserv = . if  V600253 == 0

gen religpray = .
gen religimp = .

keep year id weight pastvote currentvote undecided issuevote haveopinion21 seediff21 haveopinion22 seediff22 haveopinion23 seediff23 haveopinion24 seediff24 haveopinion25 seediff25 religid religserv religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote haveopinion21 seediff21 haveopinion22 seediff22 haveopinion23 seediff23 haveopinion24 seediff24 haveopinion25 seediff25 religid religserv religpray religimp religfine
saveold "Newmerge1960.dta", replace


**1964- Complete- religid & religserv

use NES1964.dta, clear
gen year=1964
gen weight = V640466
sum weight
replace weight = weight/(r(sum)/r(N))
gen crosssection = 1 if V640003<=2

gen pastvote = V640156
recode pastvote 1=2 2=1 3=3 4=. 5=0 6=. 7/9=.
replace pastvote=0 if V640154==5 
replace pastvote=0 if V640154==7

gen currentvote = V640286
recode currentvote  11=1 12=2 13=3  14=. 19=. 21/29=0 30=0 91=.

gen nopre=0
replace nopre = 1 if V640423==0

gen undecided = 0 
replace undecided = . if V640160 == 0
replace undecided = 1 if V640160 == 3
replace undecided = . if V640160 == 7
replace undecided = 1 if V640160 == 8
replace undecided = 1 if V640160 == 9

replace undecided = 0 if V640163>0 & V640163<=2
replace undecided = 1 if V640163 == 3
replace undecided = 0 if V640163>3 & V640163<=6
replace undecided = . if V640163== 7
replace undecided = 1 if V640163 == 8
replace undecided = . if V640163 == 9

* issuevote
*64
* school prayer = 13 + 96
* aid to other countries = 31+138
* school integration = 52 + 150
* negroes fair treatment = 160 + 53
* job stdliving = 33 + 198

* 1. prayer
gen haveopinion1 = 0 if V640081!=9
replace haveopinion1 = 1 if V640081>=1 & V640081<=5
gen seediff1 = 0 if V640081!=9 & V640083!=9
replace seediff1 = 1 if V640083==1
replace seediff1 = 1 if V640083==5
* 2. foreign aid
gen haveopinion2 = 0 if V640084!=9
replace haveopinion2 = 1 if V640084>=1 & V640084<=5
gen seediff2 = 0 if V640084!=9 & V640086!=9
replace seediff2 = 1 if V640086==1
replace seediff2 = 1 if V640086==5
* 3. school int
gen haveopinion3 = 0 if V640100!=9
replace haveopinion3 = 1 if V640100>=1 & V640100<=5
gen seediff3 = 0 if V640100!=9 & V640103!=9
replace seediff3 = 1 if V640103==1
replace seediff3 = 1 if V640103==5
* 4. negroes fair treatment
gen haveopinion4 = 0 if V640097!=9
replace haveopinion4 = 1 if V640097>=1 & V640097<=5
gen seediff4 = 0 if V640099!=9 & V640099!=9
replace seediff4 = 1 if V640099==1
replace seediff4 = 1 if V640099==5
* 5. std of living 
gen haveopinion5 = 0 if V640078!=9
replace haveopinion5 = 1 if V640078>=1 & V640078<=5
gen seediff5 = 0 if V640078!=9 & V640080!=9
replace seediff5 = 1 if V640080==1
replace seediff5 = 1 if V640080==5

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

set type double
* only include representative cross section, no need to weight
drop if crosssection!=1
replace weight = 1
gen id = V640002+19640000

gen religid = .
replace religid = 1 if  V640235 >= 100 &  V640235 <= 155 
replace religid = 2 if  V640235 == 200 
replace religid = 3 if  V640235 >= 700 &  V640235 <= 719 
replace religid = 4 if  V640235 == 300 
replace religid = 7 if  V640235 == 721
replace religid = 7 if  V640235 >= 729 &  V640235 <=  790 
replace religid = 8 if  V640235 == 728 
replace religid = 9 if  V640235 == 0 
replace religid = . if  V640235 >= 998 & V640235 <=  999 

gen religfine = .
replace religfine = 14 if V640235 == 100
replace religfine = 14 if V640235 == 101
replace religfine = 12 if V640235 == 102
replace religfine = 14 if V640235 == 109
replace religfine = 11 if V640235 == 110 
replace religfine = 11 if V640235 == 111
replace religfine = 11 if V640235 == 112
replace religfine = 12 if V640235 == 113 
replace religfine = 12 if V640235 == 114 
replace religfine = 11 if V640235 == 115
replace religfine = 11 if V640235 == 116
replace religfine = 11 if V640235 == 120
replace religfine = 13 if V640235 == 121
replace religfine = 12 if V640235 == 122
replace religfine = 12 if V640235 == 123
replace religfine = 11 if V640235 == 124
replace religfine = 14 if V640235 == 125
replace religfine = 12 if V640235 == 130
replace religfine = 12 if V640235 == 131
replace religfine = 12 if V640235 == 132
replace religfine = 12 if V640235 == 133
replace religfine = 12 if V640235 == 135
replace religfine = 12 if V640235 == 136
replace religfine = 14 if V640235 == 137
replace religfine = 12 if V640235 == 138
replace religfine = 12 if V640235 == 139
replace religfine = 12 if V640235 == 140
replace religfine = 12 if V640235 == 149
replace religfine = 14 if V640235 == 150
replace religfine = 14 if V640235 == 151
replace religfine = 14 if V640235 == 152
replace religfine = 14 if V640235 == 153
replace religfine = 14 if V640235 == 154
replace religfine = 14 if V640235 == 155
replace religfine = 2 if V640235 == 200
replace religfine = 4 if V640235 == 300
replace religfine = 3 if V640235 >= 700 & V640235 <= 719
replace religfine = 7 if V640235 == 721
replace religfine = 8 if V640235 == 728
replace religfine = 7 if V640235 == 729
replace religfine = 7 if V640235 == 790
replace religfine = 9 if V640235 == 998
replace religfine = 9 if V640235 == 0
replace religfine = . if V640235 == 999

gen religserv =  V640236
replace religserv = . if   V640236 == 9
replace religserv = . if   V640236 == 0

gen religpray = .
gen religimp = .

keep year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
saveold "Newmerge1964.dta", replace


** 1968 - Complete- religid & religserv

use NES1968.dta, clear
gen year=1968
* only include national cross-section
gen nationcs = 0
replace nationcs = 1 if V680004<5
drop if nationcs==0
*gen weight = V680003
*sum weight
*replace weight = weight/(r(sum)/r(N))

*gen nopre=0
*replace nopre = 1 if V640423==0

gen pastvote = V680129
recode pastvote 1=1 2=2 3=3 4=. 5=0 6=0 7/9=.
replace pastvote = 0 if V680127==5
replace pastvote = 0 if V680127==0

gen currentvote = V680316
recode currentvote 9=0 10/11=1 22/23=2 34/49=3 60/89=0 91/99=. 

gen undecided = 0 
replace undecided = . if V680133 == 0
replace undecided = 1 if V680133 == 3
replace undecided = 1 if V680133 == 8
replace undecided = . if V680133 == 9
replace undecided = 0 if V680134>0 & V680134<=2
replace undecided = 1 if V680134 == 3
replace undecided = 0 if V680134>3 & V680134<=7
replace undecided = 1 if V680134 == 8
replace undecided = . if V680134 == 9

* issuevote
*68
* 104 vietnam = 103
* 066 guar of jobs = 21 + 144
* 075 school int = 24 + 146
* 078 hotel rest = 24 + 161
* 098 talk w cmnst = 14 + 185

* 073 fair negroes = 30 + 163
* 096 foreign aid = 18 + 181
* 064 hospital care = 25 + 220
* 060 education = 19+279
* 062 govt too powerful = 36+378
* 100 trade w cmnst = 49 + 378

* 1. vietnam
gen haveopinion1 = 0 if V680104!=9
replace haveopinion1 = 1 if V680104>=1 & V680104<=7
gen seediff1 = 0 if V680104!=9 & V680106!=9
replace seediff1 = 1 if V680106==1
replace seediff1 = 1 if V680106==5
* 2. guar of jobs 
gen haveopinion2 = 0 if V680066!=9
replace haveopinion2 = 1 if V680066>=1 & V680066<=5
gen seediff2 = 0 if V680066!=9 & V680067!=9
replace seediff2 = 1 if V680067==1
replace seediff2 = 1 if V680067==5
* 3. school int
gen haveopinion3 = 0 if V680075!=9
replace haveopinion3 = 1 if V680075>=1 & V680075<=5
gen seediff3 = 0 if V680075!=9 & V680077!=9
replace seediff3 = 1 if V680077==1
replace seediff3 = 1 if V680077==5
* 4. hotel rest
gen haveopinion4 = 0 if V680078!=9
replace haveopinion4 = 1 if V680078>=1 & V680078<=5
gen seediff4 = 0 if V680078!=9 & V680079!=9
replace seediff4 = 1 if V680079==1
replace seediff4 = 1 if V680079==5
* 5. talk w comm 
gen haveopinion5 = 0 if V680098!=9
replace haveopinion5 = 1 if V680098>=1 & V680098<=5
gen seediff5 = 0 if V680098!=9 & V680099!=9
replace seediff5 = 1 if V680099==1
replace seediff5 = 1 if V680099==5

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

gen weight=1
set type double
gen id = V680002+19680000

gen religid = .
replace religid = 1 if  V680213 >= 100 &  V680213 <= 155 
replace religid = 2 if  V680213 == 200 
replace religid = 3 if  V680213 >= 700 &  V680213 <= 719 
replace religid = 4 if  V680213 == 300 
replace religid = 7 if  V680213 ==  790 
replace religid = 8 if  V680213 == 728 
replace religid = 9 if  V680213 == 0 
replace religid = . if  V680213 >= 998 & V680213 <=  999 

gen religfine = .
replace religfine = 14 if V680213 == 100
replace religfine = 14 if V680213 == 101
replace religfine = 12 if V680213 == 102
replace religfine = 14 if V680213 == 109
replace religfine = 11 if V680213 == 110 
replace religfine = 11 if V680213 == 111
replace religfine = 11 if V680213 == 112
replace religfine = 12 if V680213 == 113 
replace religfine = 12 if V680213 == 114 
replace religfine = 11 if V680213 == 115
replace religfine = 11 if V680213 == 116
replace religfine = 11 if V680213 == 120
replace religfine = 13 if V680213 == 121
replace religfine = 12 if V680213 == 122
replace religfine = 12 if V680213 == 123
replace religfine = 11 if V680213 == 124
replace religfine = 14 if V680213 == 125
replace religfine = 11 if V680213 == 127
replace religfine = 12 if V680213 == 130
replace religfine = 12 if V680213 == 131
replace religfine = 12 if V680213 == 132
replace religfine = 12 if V680213 == 133
replace religfine = 12 if V680213 == 134
replace religfine = 12 if V680213 == 135
replace religfine = 12 if V680213 == 136
replace religfine = 14 if V680213 == 137
replace religfine = 12 if V680213 == 138
replace religfine = 12 if V680213 == 139
replace religfine = 12 if V680213 == 140
replace religfine = 12 if V680213 == 141
replace religfine = 12 if V680213 == 149
replace religfine = 14 if V680213 == 150
replace religfine = 14 if V680213 == 151
replace religfine = 14 if V680213 == 152
replace religfine = 14 if V680213 == 153
replace religfine = 14 if V680213 == 154
replace religfine = 14 if V680213 == 155
replace religfine = 14 if V680213 == 156
replace religfine = 2 if V680213 == 200
replace religfine = 4 if V680213 == 300
replace religfine = 3 if V680213 >= 700 & V680213 <= 719
replace religfine = 7 if V680213 == 721
replace religfine = 8 if V680213 == 728
replace religfine = 7 if V680213 == 729
replace religfine = 7 if V680213 == 790
replace religfine = 9 if V680213 == 998
replace religfine = 9 if V680213 == 0
replace religfine = . if V680213 == 999

gen religserv = V680214
replace religserv = . if  V680214 == 9

gen religpray = .
gen religimp = .

keep year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
saveold "Newmerge1968.dta", replace


** 1972- Complete- religid, religserv, religpray

use NES1972.dta, clear
gen year=1972
*gen nopre=0
*replace nopre = 1 if V640423==0

gen pastvote = 0 if V720159==5
replace pastvote = 0 if V720156==0
replace pastvote = 0 if V720156==5
replace pastvote = 1 if V720160==1
replace pastvote = 2 if V720160==2
replace pastvote = 3 if V720160==3
replace pastvote = 3 if V720160==5

gen currentvote = 0 if V720477==5
replace currentvote = 1 if V720478==2
replace currentvote = 2 if V720478==1
replace currentvote = 3 if V720478==3

gen undecided = 0 
replace undecided = . if V720170 == 0
replace undecided = 1 if V720170 == 3
replace undecided = 1 if V720170 == 8
replace undecided = . if V720170 == 9

replace undecided = 0 if V720171>0 & V720171<=2
replace undecided = 1 if V720171 == 3
replace undecided = 0 if V720171>3 & V720171<=7
replace undecided = 1 if V720171 == 8
replace undecided = . if V720171 == 9

* 1972 had 2 forms, each with different issue items
gen form1 = 0 
replace form1 = 1 if 10<=V720003 & V720003<=13
gen form2 = 0 
replace form2 = 1 if 20<=V720003 & V720003<=24

** Issues 72
* form1, Health Insurance, 95 DK/haven't thought
*tab V720208 if form1==1
* form2, Gov inflation, 63 DK/haven't thought
*tab V720190 if form2==1

* form1, gov see to job, 72 DK/haven't thought
tab V720172 if form1==1
gen haveopinion1 = 0 if form1==1
replace haveopinion1 = . if V720172==9
replace haveopinion1 = 1 if V720172>0 & V720172<=7
gen seediff1 = 0 if haveopinion1!=.
replace seediff1 = 1 if V720173!=0 & V720173!=V720174 & V720173!=8 & V720174!=8
replace seediff1 = . if V720173==9
replace seediff1 = . if V720174==9
* form1, tax rate scale, 74 DK/haven't thought
tab V720178 if form1==1
gen haveopinion2 = 0  if form1==1
replace haveopinion2 = . if V720178==9
replace haveopinion2 = 1 if V720178>0 & V720178<=7
gen seediff2 = 0 if haveopinion2!=.
replace seediff2 = 1 if V720179!=0 & V720179!=V720180 & V720179!=8 & V720180!=8
replace seediff2 = . if V720179==9
replace seediff2 = . if V720180==9

* form2, Vietnam withdrawal, 37 DK/haven't thought
tab V720184 if form2==1
replace haveopinion1 = 0 if form2==1 & V720184!=9
replace haveopinion1 = 1 if V720184>0 & V720184<=7
replace seediff1 = 0 if V720185==8
replace seediff1 = 0 if V720186==8
replace seediff1 = 0 if V720185==V720186
replace seediff1 = 1 if V720185!=0 & V720185!=V720186 & seediff1==.
replace seediff1 = . if V720185==9
replace seediff1 = . if V720186==9
* form2, Gov polution, 50 DK/haven't thought
tab V720214 if form2==1
replace haveopinion2 = 0 if form2==1 & V720214!=9
replace haveopinion2 = 1 if V720214>0 & V720214<=7
replace seediff2 = 0 if V720215==8
replace seediff2 = 0 if V720216==8
replace seediff2 = 0 if V720215==V720216
replace seediff2 = 1 if V720215!=0 & V720215!=V720216 & seediff2==.
replace seediff2 = . if V720215==9
replace seediff2 = . if V720216==9

* Marijuana, 61 Dk/Haven't thought
tab V720196
gen haveopinion3 = 0 if V720196<=8
replace haveopinion3 = 1 if V720196>=1 & V720196<=7
gen seediff3 = 0 if haveopinion3==0
replace seediff3 = 0 if V720197==8
replace seediff3 = 0 if V720198==8
replace seediff3 = 0 if V720198==V720197 & V720197<=8 & V720198<=8
replace seediff3 = 1 if 1<=V720198 & V720198<=7 & 1<=V720197 & V720197<=7 & V720197!=V720198
replace seediff3 = . if V720197==9
replace seediff3 = . if V720198==9

* School Busing, 60 DK/Haven't thought
tab V720202
gen haveopinion4 = 0 if V720202<=8
replace haveopinion4 = 1 if V720202>=1 & V720202<=7
gen seediff4 = 0 if haveopinion4==0
replace seediff4 = 0 if V720203==8
replace seediff4 = 0 if V720204==8
replace seediff4 = 0 if V720203==V720204 & V720203<=8 & V720204<=8
replace seediff4 = 1 if 1<=V720203 & V720203<=7 & 1<=V720204 & V720204<=7 & V720203!=V720204
replace seediff4 = . if V720203==9
replace seediff4 = . if V720204==9

* Women's rights, 45 DK/Haven't thought
tab V720232 
gen haveopinion5 = 0 if V720232<=8
replace haveopinion5 = 1 if V720232>=1 & V720232<=7
gen seediff5 = 0 if haveopinion5==0
replace seediff5 = 0 if V720233==8
replace seediff5 = 0 if V720234==8
replace seediff5 = 0 if V720233==V720234 & V720233<=8 & V720234<=8
replace seediff5 = 1 if 1<=V720233 & V720233<=7 & 1<=V720234 & V720234<=7 & V720233!=V720234
replace seediff5 = . if V720233==9
replace seediff5 = . if V720234==9

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

gen weight=1
set type double
gen id = V720002+19720000

gen religid = .
replace religid = 1 if  V720422 >= 100 &  V720422 <= 156 
replace religid = 2 if  V720422 == 200 
replace religid = 3 if  V720422 >= 700 &  V720422 <= 719 
replace religid = 4 if  V720422 == 300
replace religid = 7 if  V720422 >= 720 & V720422 <= 723 
replace religid = 7 if  V720422 == 790 
replace religid = 8 if  V720422 == 728 
replace religid = 9 if  V720422 == 998 
replace religid = . if  V720422 ==  999 

gen religfine = .
replace religfine = 14 if V720422 == 100
replace religfine = 14 if V720422 == 101
replace religfine = 12 if V720422 == 102
replace religfine = 14 if V720422 == 109
replace religfine = 11 if V720422 == 110 
replace religfine = 11 if V720422 == 111
replace religfine = 11 if V720422 == 112
replace religfine = 12 if V720422 == 113 
replace religfine = 12 if V720422 == 114 
replace religfine = 11 if V720422 == 115
replace religfine = 11 if V720422 == 116
replace religfine = 11 if V720422 == 120
replace religfine = 13 if V720422 == 121
replace religfine = 12 if V720422 == 122
replace religfine = 12 if V720422 == 123
replace religfine = 11 if V720422 == 124
replace religfine = 14 if V720422 == 125
replace religfine = 12 if V720422 == 126
replace religfine = 11 if V720422 == 127
replace religfine = 12 if V720422 == 130
replace religfine = 12 if V720422 == 131
replace religfine = 12 if V720422 == 132
replace religfine = 12 if V720422 == 133
replace religfine = 12 if V720422 == 134
replace religfine = 12 if V720422 == 135
replace religfine = 12 if V720422 == 136
replace religfine = 14 if V720422 == 137
replace religfine = 12 if V720422 == 138
replace religfine = 12 if V720422 == 139
replace religfine = 12 if V720422 == 140
replace religfine = 12 if V720422 == 141
replace religfine = 12 if V720422 == 149
replace religfine = 14 if V720422 == 150
replace religfine = 14 if V720422 == 151
replace religfine = 14 if V720422 == 152
replace religfine = 14 if V720422 == 153
replace religfine = 14 if V720422 == 154
replace religfine = 14 if V720422 == 155
replace religfine = 14 if V720422 == 156
replace religfine = 2 if V720422 == 200
replace religfine = 4 if V720422 == 300
replace religfine = 3 if V720422 >= 700 & V720422 <= 719
replace religfine = 7 if V720422 == 721
replace religfine = 8 if V720422 == 728
replace religfine = 7 if V720422 == 729
replace religfine = 7 if V720422 == 790
replace religfine = 9 if V720422 == 998
replace religfine = 9 if V720422 == 0
replace religfine = . if V720422 == 999

gen religserv =  V720423
replace religserv = . if   V720423 == 9
replace religserv = . if   V720423 == 0

gen religpray =  V720932
replace religpray = . if  V720932 == 9
replace religpray = . if  V720932 == 8
replace religpray = . if  V720932 == 0 

gen religimp = .
 
keep year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
saveold "Newmerge1972.dta", replace


** 1976 - Complete religid and religserv

use NES1976.dta, clear
gen year=1976
gen weight = V763003
sum weight
replace weight = weight/(r(sum)/r(N))

gen pastvote = .
replace pastvote = 0 if V763179==0
replace pastvote = 0 if V763179==5
replace pastvote = 0 if V763182==5
replace pastvote = 1 if V763183==2
replace pastvote = 2 if V763183==1
replace pastvote = 3 if V763183==5

gen currentvote = .
replace currentvote = 0 if V763655==5
replace currentvote = 0 if V763665==7
replace currentvote = 1 if V763665==2
replace currentvote = 2 if V763665==1
replace currentvote = 3 if V763665==3
replace currentvote = 3 if V763665==4
replace currentvote = 3 if V763665==5

gen undecided = 0 
replace undecided = . if V763044 == 0
replace undecided = 1 if V763044 == 3
replace undecided = 1 if V763044 == 8
replace undecided = . if V763044 == 9

replace undecided = 0 if V763045>0 & V763045<=2
replace undecided = 1 if V763045 == 3
replace undecided = 0 if V763045>3 & V763045<=7
replace undecided = 1 if V763045 == 8
replace undecided = . if V763045 == 9

** Issues 76
* Guar job
tab V763241 [iw=weight]
gen haveopinion1 = 0 if V763241<=8 & V763004!=3
replace haveopinion1 =1 if V763241>0 & V763241<=7
gen seediff1 = 0 if haveopinion1 ==0
replace seediff1 = 0 if V763242==8
replace seediff1 = 0 if V763243==8
replace seediff1 = 0 if V763243==V763242 & V763243<=8 & V763242<=8
replace seediff1 = 1 if 1<=V763242 & V763242<=7 & 1<=V763243 & V763243<=7 & V763242!=V763243
replace seediff1 = . if V763242==9
replace seediff1 = . if V763243==9
replace seediff1 = . if haveopinion1==.

* Crime/Rights 
tab V763248
gen haveopinion2 = 0 if V763248<=8 & V763004!=3
replace haveopinion2 =1 if V763248>0 & V763248<=7
gen seediff2 = 0 if haveopinion2 ==0
replace seediff2 = 0 if V763249==8
replace seediff2 = 0 if V763250==8
replace seediff2 = 0 if V763249==V763250 & V763249<=8 & V763250<=8
replace seediff2 = 1 if 1<=V763249 & V763249<=7 & 1<=V763250 & V763250<=7 & V763249!=V763250
replace seediff2 = . if V763249==9
replace seediff2 = . if V763250==9
replace seediff2 = . if haveopinion2==.

* Bussing
tab V763257
gen haveopinion3 = 0 if V763257<=8 & V763004!=3
replace haveopinion3 =1 if V763257>0 & V763257<=7
gen seediff3 = 0 if haveopinion3 ==0
replace seediff3 = 0 if V763258==8
replace seediff3 = 0 if V763259==8
replace seediff3 = 0 if V763258==V763259 & V763258<=8 & V763259<=8
replace seediff3 = 1 if 1<=V763258 & V763258<=7 & 1<=V763259 & V763259<=7 & V763258!=V763259
replace seediff3 = . if V763258==9
replace seediff3 = . if V763259==9
replace seediff3 = . if haveopinion3==.

* Minority Aid
tab V763264
gen haveopinion4 = 0 if V763264<=8 & V763004!=3
replace haveopinion4 =1 if V763264>0 & V763264<=7
gen seediff4 = 0 if haveopinion4 ==0
replace seediff4 = 0 if V763265==8
replace seediff4 = 0 if V763266==8
replace seediff4 = 0 if V763265==V763266 & V763265<=8 & V763266<=8
replace seediff4 = 1 if 1<=V763265 & V763265<=7 & 1<=V763266 & V763266<=7 & V763265!=V763266
replace seediff4 = . if V763265==9
replace seediff4 = . if V763266==9
replace seediff4 = . if haveopinion4==.

* Medical insurance
tab V763273
gen haveopinion5 = 0 if V763273<=8 & V763004!=3
replace haveopinion5 =1 if V763273>0 & V763273<=7
gen seediff5 = 0 if haveopinion5 ==0
replace seediff5 = 0 if V763274==8
replace seediff5 = 0 if V763275==8
replace seediff5 = 0 if V763274==V763275 & V763274<=8 & V763275<=8
replace seediff5 = 1 if 1<=V763274 & V763274<=7 & 1<=V763275 & V763275<=7 & V763274!=V763275
replace seediff5 = . if V763274==9
replace seediff5 = . if V763275==9
replace seediff5 = . if haveopinion5==.

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

set type double
gen id = V763002+19760000

gen religid = .
replace religid = 1 if  V763510 >= 100 &  V763510 <= 156 
replace religid = 2 if  V763510 == 200 
replace religid = 3 if  V763510 >= 700 &  V763510 <= 719 
replace religid = 4 if  V763510 == 300
replace religid = 7 if  V763510 >= 720 & V763510 <= 723 
replace religid = 7 if  V763510 == 790 
replace religid = 8 if  V763510 == 728 
replace religid = 9 if  V763510 == 998 
replace religid = . if  V763510 ==  999 

gen religfine = .
replace religfine = 14 if V763510 == 100
replace religfine = 14 if V763510 == 101
replace religfine = 12 if V763510 == 102
replace religfine = 14 if V763510 == 109
replace religfine = 11 if V763510 == 110 
replace religfine = 11 if V763510 == 111
replace religfine = 11 if V763510 == 112
replace religfine = 12 if V763510 == 113 
replace religfine = 12 if V763510 == 114 
replace religfine = 11 if V763510 == 115
replace religfine = 11 if V763510 == 116
replace religfine = 11 if V763510 == 120
replace religfine = 13 if V763510 == 121
replace religfine = 12 if V763510 == 122
replace religfine = 12 if V763510 == 123
replace religfine = 11 if V763510 == 124
replace religfine = 14 if V763510 == 125
replace religfine = 12 if V763510 == 126
replace religfine = 11 if V763510 == 127
replace religfine = 12 if V763510 == 130
replace religfine = 12 if V763510 == 131
replace religfine = 12 if V763510 == 132
replace religfine = 12 if V763510 == 133
replace religfine = 12 if V763510 == 134
replace religfine = 12 if V763510 == 135
replace religfine = 12 if V763510 == 136
replace religfine = 14 if V763510 == 137
replace religfine = 12 if V763510 == 138
replace religfine = 12 if V763510 == 139
replace religfine = 12 if V763510 == 140
replace religfine = 12 if V763510 == 141
replace religfine = 12 if V763510 == 149
replace religfine = 14 if V763510 == 150
replace religfine = 14 if V763510 == 151
replace religfine = 14 if V763510 == 152
replace religfine = 14 if V763510 == 153
replace religfine = 14 if V763510 == 154
replace religfine = 14 if V763510 == 155
replace religfine = 14 if V763510 == 156
replace religfine = 2 if V763510 == 200
replace religfine = 4 if V763510 == 300
replace religfine = 3 if V763510 >= 700 & V763510 <= 719
replace religfine = 7 if V763510 >= 720 & V763510 <= 723
replace religfine = 8 if V763510 == 728
replace religfine = 7 if V763510 == 729
replace religfine = 7 if V763510 == 790
replace religfine = 9 if V763510 == 998
replace religfine = 9 if V763510 == 0
replace religfine = . if V763510 == 999

gen religserv =   V763511
replace religserv = . if V763511 == 9
replace religserv = . if V763511 == 8
replace religserv = . if V763511 == 0

gen religpray = .
gen religimp = .

keep year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv  religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
saveold "Newmerge1976.dta", replace


** 1980 - Complete- religid, religserv, religimp

use NES1980.dta, clear
gen year=1980

gen pastvote = .
replace pastvote = 0 if V800350==0
replace pastvote = 0 if V800350==5
replace pastvote = 0 if V800353==5
replace pastvote = 1 if V800354==2
replace pastvote = 2 if V800354==1
replace pastvote = 3 if V800354==5

gen currentvote = .
replace currentvote = 0 if V800993==5
replace currentvote = 0 if V800988==5
replace currentvote = 1 if V800994==2
replace currentvote = 2 if V800994==1
replace currentvote = 3 if V800994==5
replace currentvote = 3 if V800994==6
replace currentvote = 3 if V800994==7

gen undecided = 0 
replace undecided = . if V800137 == 9
replace undecided = 1 if V800137 == 8

** Issues 80, only 5 pre-election
* def. spend 800281, 201+38
* gov services 800291, 219 + 78
* inflation 800301, 417 + 219
* abortion 800311, 39
* tax cut 800322, 437 + 147

tab V800281 
gen haveopinion1 = 0 if V800281<=8 
replace haveopinion1 =1 if V800281>0 & V800281<=7
gen seediff1 = 0 if haveopinion1 ==0
replace seediff1 = 0 if V800282==8
replace seediff1 = 0 if V800283==8
replace seediff1 = 0 if V800282==V800283 & V800282<=8 & V800283<=8
replace seediff1 = 1 if 1<=V800282 & V800282<=7 & 1<=V800283 & V800283<=7 & V800282!=V800283
replace seediff1 = . if V800282==9
replace seediff1 = . if V800283==9
replace seediff1 = . if haveopinion1==.
 
tab V800291
gen haveopinion2 = 0 if V800291<=8 
replace haveopinion2 =1 if V800291>0 & V800291<=7
gen seediff2 = 0 if haveopinion2 ==0
replace seediff2 = 0 if V800292==8
replace seediff2 = 0 if V800293==8
replace seediff2 = 0 if V800292==V800293 & V800292<=8 & V800293<=8
replace seediff2 = 1 if 1<=V800292 & V800292<=7 & 1<=V800293 & V800293<=7 & V800292!=V800293
replace seediff2 = . if V800292==9
replace seediff2 = . if V800293==9
replace seediff2 = . if haveopinion2==.

tab V800301
gen haveopinion3 = 0 if V800301<=8 
replace haveopinion3 =1 if V800301>0 & V800301<=7
gen seediff3 = 0 if haveopinion3 ==0
replace seediff3 = 0 if V800302==8
replace seediff3 = 0 if V800303==8
replace seediff3 = 0 if V800302==V800303 & V800302<=8 & V800303<=8
replace seediff3 = 1 if 1<=V800302 & V800302<=7 & 1<=V800303 & V800303<=7 & V800302!=V800303
replace seediff3 = . if V800302==9
replace seediff3 = . if V800303==9
replace seediff3 = . if haveopinion3==.

tab V800311
gen haveopinion4 = 0 if V800311<=8 
replace haveopinion4 =1 if V800311>0 & V800311<=7
gen seediff4 = 0 if haveopinion4 ==0
replace seediff4 = 0 if V800312==8
replace seediff4 = 0 if V800313==8
replace seediff4 = 0 if V800312==V800313 & V800312<=8 & V800313<=8
replace seediff4 = 1 if 1<=V800312 & V800312<=7 & 1<=V800313 & V800313<=7 & V800312!=V800313
replace seediff4 = . if V800312==9
replace seediff4 = . if V800313==9
replace seediff4 = . if haveopinion4==.

tab V800322
gen haveopinion5 = 0 if V800322<=8 
replace haveopinion5 =1 if V800322==1
replace haveopinion5 =0 if V800323==8
gen seediff5 = 0 if haveopinion5 ==0
replace seediff5 = 0 if V800324==8
replace seediff5 = 0 if V800325==8
replace seediff5 = 0 if V800324==V800325 & V800324<=8 & V800325<=8
replace seediff5 = 1 if 1<=V800324 & V800324<=7 & 1<=V800325 & V800325<=7 & V800324!=V800325
replace seediff5 = . if V800324==9
replace seediff5 = . if V800325==9
replace seediff5 = . if haveopinion5==.

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

gen weight=1
set type double
gen id = V800004+19800000

gen religid = .
replace religid = 1 if  V800693 >= 100 &  V800693 <= 156 
replace religid = 2 if  V800693 == 200 
replace religid = 3 if  V800693 >= 700 &  V800693 <= 719 
replace religid = 4 if  V800693 == 300
replace religid = 7 if  V800693 >= 720 & V800693 <= 723 
replace religid = 7 if  V800693 == 729
replace religid = 7 if  V800693 == 790 
replace religid = 8 if  V800693 == 728 
replace religid = 9 if  V800693 == 998 
replace religid = . if  V800693 ==  999 

gen religfine = .
replace religfine = 14 if V800693 == 100
replace religfine = 14 if V800693 == 101
replace religfine = 12 if V800693 == 102
replace religfine = 14 if V800693 == 109
replace religfine = 11 if V800693 == 110 
replace religfine = 11 if V800693 == 111
replace religfine = 11 if V800693 == 112
replace religfine = 12 if V800693 == 113 
replace religfine = 12 if V800693 == 114 
replace religfine = 11 if V800693 == 115
replace religfine = 11 if V800693 == 116
replace religfine = 11 if V800693 == 120
replace religfine = 13 if V800693 == 121
replace religfine = 12 if V800693 == 122
replace religfine = 12 if V800693 == 123
replace religfine = 11 if V800693 == 124
replace religfine = 14 if V800693 == 125
replace religfine = 12 if V800693 == 126
replace religfine = 11 if V800693 == 127
replace religfine = 12 if V800693 == 130
replace religfine = 12 if V800693 == 131
replace religfine = 12 if V800693 == 132
replace religfine = 12 if V800693 == 133
replace religfine = 12 if V800693 == 134
replace religfine = 12 if V800693 == 135
replace religfine = 12 if V800693 == 136
replace religfine = 14 if V800693 == 137
replace religfine = 12 if V800693 == 138
replace religfine = 12 if V800693 == 139
replace religfine = 12 if V800693 == 140
replace religfine = 12 if V800693 == 141
replace religfine = 12 if V800693 == 149
replace religfine = 14 if V800693 == 150
replace religfine = 14 if V800693 == 151
replace religfine = 14 if V800693 == 152
replace religfine = 14 if V800693 == 153
replace religfine = 14 if V800693 == 154
replace religfine = 14 if V800693 == 155
replace religfine = 14 if V800693 == 156
replace religfine = 2 if V800693 == 200
replace religfine = 4 if V800693 == 300
replace religfine = 3 if V800693 >= 700 & V800693 <= 719
replace religfine = 7 if V800693 >= 720 & V800693 <= 723
replace religfine = 8 if V800693 == 728
replace religfine = 7 if V800693 == 729
replace religfine = 7 if V800693 == 790
replace religfine = 9 if V800693 == 998
replace religfine = 9 if V800693 == 0
replace religfine = . if V800693 == 999

gen religserv =  V800694
replace religserv = . if  V800694 == 8
replace religserv = . if  V800694 == 9
replace religserv = . if  V800694 == 0
 
gen religpray = .

gen religimp =  V801173
replace religimp = . if   V801173 == 9
replace religimp = . if   V801173 == 8
replace religimp = 0 if   V801173 == 5

keep year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
saveold "Newmerge1980.dta", replace


** 1984 -Complete- religid, religserv, religimp

use NES1984.dta, clear
gen year=1984

gen undecided = 0 
replace undecided = . if V840425 == 9
replace undecided = . if V840425 == 0
replace undecided = 1 if V840425 == 8

** Issues 84, 
* aid to minorities 840382, 24+263=287
* defense spending 840395, 37+258=295
* tough with russia 840408, 65 + 241 = 306
* jobs living, 840414, 266+40 = 306
* gov services 840375, 30+333=363

* gov help women 849401, 29+324=353, but candidate placement much weaker
* central america 840388, 67+467
* womens role, 840250, 31 + 183 (no reagan/mondale)
* abortion, 840423(no reagan/mondale)

tab V840382 
gen haveopinion1 = 0 if V840382<=8 
replace haveopinion1 =1 if V840382>0 & V840382<=7
gen seediff1 = 0 if haveopinion1 ==0
replace seediff1 = 0 if V840383==8
replace seediff1 = 0 if V840384==8
replace seediff1 = 0 if V840383==V840384 & V840383<=8 & V840384<=8
replace seediff1 = 1 if 1<=V840383 & V840383<=7 & 1<=V840384 & V840384<=7 & V840383!=V840384
replace seediff1 = . if V840383==9
replace seediff1 = . if V840384==9
replace seediff1 = . if haveopinion1==.
 
tab V840395
gen haveopinion2 = 0 if V840395<=8 
replace haveopinion2 =1 if V840395>0 & V840395<=7
gen seediff2 = 0 if haveopinion2 ==0
replace seediff2 = 0 if V840396==8
replace seediff2 = 0 if V840397==8
replace seediff2 = 0 if V840396==V840397 & V840396<=8 & V840397<=8
replace seediff2 = 1 if 1<=V840396 & V840396<=7 & 1<=V840397 & V840397<=7 & V840396!=V840397
replace seediff2 = . if V840396==9
replace seediff2 = . if V840397==9
replace seediff2 = . if haveopinion2==.

tab V840408
gen haveopinion3 = 0 if V840408<=8 
replace haveopinion3 =1 if V840408>0 & V840408<=7
gen seediff3 = 0 if haveopinion3 ==0
replace seediff3 = 0 if V840409==8
replace seediff3 = 0 if V840410==8
replace seediff3 = 0 if V840409==V840410 & V840409<=8 & V840410<=8
replace seediff3 = 1 if 1<=V840409 & V840409<=7 & 1<=V840410 & V840410<=7 & V840409!=V840410
replace seediff3 = . if V840409==9
replace seediff3 = . if V840410==9
replace seediff3 = . if haveopinion3==.

tab V840414
gen haveopinion4 = 0 if V840414<=8 
replace haveopinion4 =1 if V840414>0 & V840414<=7
gen seediff4 = 0 if haveopinion4 ==0
replace seediff4 = 0 if V840415==8
replace seediff4 = 0 if V840416==8
replace seediff4 = 0 if V840415==V840416 & V840415<=8 & V840416<=8
replace seediff4 = 1 if 1<=V840415 & V840415<=7 & 1<=V840416 & V840416<=7 & V840415!=V840416
replace seediff4 = . if V840415==9
replace seediff4 = . if V840416==9
replace seediff4 = . if haveopinion4==.

tab V840375
gen haveopinion5 = 0 if V840375<=8 
replace haveopinion5 =1 if V840375>0 & V840375<=7
gen seediff5 = 0 if haveopinion5 ==0
replace seediff5 = 0 if V840376==8
replace seediff5 = 0 if V840377==8
replace seediff5 = 0 if V840376==V840377 & V840376<=8 & V840377<=8
replace seediff5 = 1 if 1<=V840376 & V840376<=7 & 1<=V840377 & V840377<=7 & V840376!=V840377
replace seediff5 = . if V840376==9
replace seediff5 = . if V840377==9
replace seediff5 = . if haveopinion5==.

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

** no record of past vote to compare to current vote
gen pastvote = .
gen currentvote = .

gen weight=1
set type double
gen id = V840004+19840000

gen religid =  .  
replace religid = 1 if  V840687 >= 100 &  V840687 <= 156 
replace religid = 2 if  V840687 == 200 
replace religid = 3 if  V840687 >= 700 &  V840687 <= 719 
replace religid = 4 if  V840687 == 300
replace religid = 7 if  V840687 >= 720 &  V840687 <= 723 
replace religid = 7 if  V840687 == 729
replace religid = 7 if  V840687 == 790 
replace religid = 8 if  V840687 == 800 
replace religid = 9 if  V840687 == 998 
replace religid = . if  V840687 == 999
replace religid = . if  V840687 == 996

gen religfine = .
replace religfine = 14 if V840687 == 100
replace religfine = 14 if V840687 == 101
replace religfine = 12 if V840687 == 102
replace religfine = 14 if V840687 == 109
replace religfine = 11 if V840687 == 110 
replace religfine = 11 if V840687 == 111
replace religfine = 11 if V840687 == 112
replace religfine = 12 if V840687 == 113 
replace religfine = 12 if V840687 == 114 
replace religfine = 11 if V840687 == 115
replace religfine = 11 if V840687 == 116
replace religfine = 11 if V840687 == 120
replace religfine = 13 if V840687 == 121
replace religfine = 12 if V840687 == 122
replace religfine = 12 if V840687 == 123
replace religfine = 11 if V840687 == 124
replace religfine = 14 if V840687 == 125
replace religfine = 14 if V840687 == 126
replace religfine = 11 if V840687 == 127
replace religfine = 12 if V840687 == 130
replace religfine = 12 if V840687 == 131
replace religfine = 12 if V840687 == 132
replace religfine = 12 if V840687 == 133
replace religfine = 12 if V840687 == 134
replace religfine = 12 if V840687 == 135
replace religfine = 12 if V840687 == 136
replace religfine = 14 if V840687 == 137
replace religfine = 12 if V840687 == 138
replace religfine = 12 if V840687 == 139
replace religfine = 12 if V840687 == 140
replace religfine = 12 if V840687 == 141
replace religfine = 12 if V840687 == 149
replace religfine = 14 if V840687 == 150
replace religfine = 14 if V840687 == 151
replace religfine = 14 if V840687 == 152
replace religfine = 14 if V840687 == 153
replace religfine = 14 if V840687 == 154
replace religfine = 14 if V840687 == 155
replace religfine = 14 if V840687 == 156
replace religfine = 2 if V840687 == 200
replace religfine = 4 if V840687 == 300
replace religfine = 3 if V840687 >= 700 & V840687 <= 719
replace religfine = 7 if V840687 >= 720 & V840687 <= 723
replace religfine = 8 if V840687 == 728
replace religfine = 7 if V840687 == 729
replace religfine = 7 if V840687 == 790
replace religfine = 9 if V840687 == 998
replace religfine = 9 if V840687 == 0
replace religfine = . if V840687 == 999

gen religserv =  V840688
replace religserv = . if  V840688 == 8
replace religserv = . if  V840688 == 9
replace religserv = . if  V840688 == 0

gen religpray = .
 
gen religimp =   V841078
replace religimp = . if   V841078 == 9
replace religimp = . if   V841078 == 8
replace religimp = 0 if   V841078 == 5

keep year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
saveold "Newmerge1984.dta", replace

** 1988 - Complete

use NES1988.dta, clear
gen year=1988

gen pastvote = .
replace pastvote = 0 if V880630==5
replace pastvote = 1 if V880631==2
replace pastvote = 2 if V880631==1
replace pastvote = 3 if V880631==5

gen currentvote = .
replace currentvote = 0 if V880756==5
replace currentvote = 0 if V880762==5
replace currentvote = 1 if V880763==2
replace currentvote = 2 if V880763==1
replace currentvote = 3 if V880763==7

gen undecided = 0 
replace undecided = . if V880397 == 9
replace undecided = . if V880397 == 0
replace undecided = 1 if V880397 == 8

** Issues 88, 
* women's role, 880387, 11+104 = 115
* aid to minorities 880332, form a, 9+1133= 1142-1006 = 136
* aid to minorities 880340, form b, 12+1113=1125 -1034=89 = 225
* defense spending 880310, 12+264=276
* jobs living, 880323, 24+276 = 300
* health insurance 880318, 31+290 = 321
* cooperate with russia 880368, 26+298 = 324
* gov services,  880302, 21+395 = 416

tab V880387 
gen haveopinion1 = 0 if V880387<=8 
replace haveopinion1 =1 if V880387>0 & V880387<=7
gen seediff1 = 0 if haveopinion1 ==0
replace seediff1 = 0 if V880388==8
replace seediff1 = 0 if V880389==8
replace seediff1 = 0 if V880388==V880389 & V880388<=8 & V880389<=8
replace seediff1 = 1 if 1<=V880388 & V880388<=7 & 1<=V880389 & V880389<=7 & V880388!=V880389
replace seediff1 = . if V880388==9
replace seediff1 = . if V880389==9
replace seediff1 = . if haveopinion1==.
 
gen form = V880399
tab V880332 if form==1
tab V880340 if form==2
gen haveopinion2 = 0 if V880332<=8 & form==1
replace haveopinion2 =1 if V880332>0 & V880332<=7 & form==1
replace haveopinion2 =0 if V880340<=8 & form==2
replace haveopinion2 =1 if V880340>0 & V880340<=7 & form==2
gen seediff2 = 0 if haveopinion2 ==0
replace seediff2 = 0 if V880333==8 & form==1
replace seediff2 = 0 if V880334==8 & form==1
replace seediff2 = 0 if V880341==8 & form==2
replace seediff2 = 0 if V880342==8 & form==2
replace seediff2 = 0 if V880333==V880334 & V880333<=8 & V880334<=8 & form==1
replace seediff2 = 1 if 1<=V880333 & V880333<=7 & 1<=V880334 & V880334<=7 & V880333!=V880334 & form==1
replace seediff2 = 0 if V880341==V880342 & V880341<=8 & V880342<=8 & form==2
replace seediff2 = 1 if 1<=V880341 & V880341<=7 & 1<=V880342 & V880342<=7 & V880341!=V880342 & form==2
replace seediff2 = . if V880333==9 & form==1
replace seediff2 = . if V880334==9 & form==1
replace seediff2 = . if V880341==9 & form==2
replace seediff2 = . if V880342==9 & form==2
replace seediff2 = . if haveopinion2==.

tab V880310
gen haveopinion3 = 0 if V880310<=8 
replace haveopinion3 =1 if V880310>0 & V880310<=7
gen seediff3 = 0 if haveopinion3 ==0
replace seediff3 = 0 if V880311==8
replace seediff3 = 0 if V880312==8
replace seediff3 = 0 if V880311==V880312 & V880311<=8 & V880312<=8
replace seediff3 = 1 if 1<=V880311 & V880311<=7 & 1<=V880312 & V880312<=7 & V880311!=V880312
replace seediff3 = . if V880311==9
replace seediff3 = . if V880312==9
replace seediff3 = . if haveopinion3==.

tab V880323
gen haveopinion4 = 0 if V880323<=8 
replace haveopinion4 =1 if V880323>0 & V880323<=7
gen seediff4 = 0 if haveopinion4 ==0
replace seediff4 = 0 if V880324==8
replace seediff4 = 0 if V880325==8
replace seediff4 = 0 if V880324==V880325 & V880324<=8 & V880325<=8
replace seediff4 = 1 if 1<=V880324 & V880324<=7 & 1<=V880325 & V880325<=7 & V880324!=V880325
replace seediff4 = . if V880324==9
replace seediff4 = . if V880325==9
replace seediff4 = . if haveopinion4==.

tab V880318
gen haveopinion5 = 0 if V880318<=8 
replace haveopinion5 =1 if V880318>0 & V880318<=7
gen seediff5 = 0 if haveopinion5 ==0
replace seediff5 = 0 if V880319==8
replace seediff5 = 0 if V880320==8
replace seediff5 = 0 if V880319==V880320 & V880319<=8 & V880320<=8
replace seediff5 = 1 if 1<=V880319 & V880319<=7 & 1<=V880320 & V880320<=7 & V880319!=V880320
replace seediff5 = . if V880319==9
replace seediff5 = . if V880320==9
replace seediff5 = . if haveopinion5==.

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

gen weight=1
set type double
gen id = V880004+19880000

gen religid =  .  
replace religid = 1 if  V880527 >= 100 &  V880527 <= 156 
replace religid = 2 if  V880527 == 200 
replace religid = 3 if  V880527 >= 700 &  V880527 <= 719 
replace religid = 4 if  V880527 == 300
replace religid = 7 if  V880527 >= 720 &  V880527 <= 723 
replace religid = 7 if  V880527 == 790 
replace religid = 8 if  V880527 == 800 
replace religid = 9 if  V880527 == 998 
replace religid = . if  V880527 == 999
replace religid = . if  V880527 == 996

gen religfine = .
replace religfine = 14 if V880527  == 100
replace religfine = 14 if V880527  == 101
replace religfine = 12 if V880527  == 102
replace religfine = 14 if V880527  == 109
replace religfine = 11 if V880527  == 110 
replace religfine = 11 if V880527  == 111
replace religfine = 11 if V880527  == 112
replace religfine = 12 if V880527  == 113 
replace religfine = 12 if V880527  == 114 
replace religfine = 11 if V880527  == 115
replace religfine = 11 if V880527  == 116
replace religfine = 11 if V880527  == 120
replace religfine = 13 if V880527  == 121
replace religfine = 12 if V880527  == 122
replace religfine = 12 if V880527  == 123
replace religfine = 11 if V880527  == 124
replace religfine = 14 if V880527  == 125
replace religfine = 14 if V880527  == 126
replace religfine = 11 if V880527  == 127
replace religfine = 12 if V880527  == 130
replace religfine = 12 if V880527  == 131
replace religfine = 12 if V880527  == 132
replace religfine = 12 if V880527  == 133
replace religfine = 12 if V880527  == 134
replace religfine = 12 if V880527  == 135
replace religfine = 12 if V880527  == 136
replace religfine = 14 if V880527  == 137
replace religfine = 12 if V880527  == 138
replace religfine = 12 if V880527  == 139
replace religfine = 12 if V880527  == 140
replace religfine = 12 if V880527  == 141
replace religfine = 12 if V880527  == 149
replace religfine = 14 if V880527  == 150
replace religfine = 14 if V880527  == 151
replace religfine = 14 if V880527  == 152
replace religfine = 14 if V880527  == 153
replace religfine = 14 if V880527  == 154
replace religfine = 14 if V880527  == 155
replace religfine = 14 if V880527  == 156
replace religfine = 2 if V880527  == 200
replace religfine = 4 if V880527  == 300
replace religfine = 3 if V880527  >= 700 & V880527  <= 719
replace religfine = 7 if V880527  >= 720 & V880527  <= 723
replace religfine = 8 if V880527  == 728
replace religfine = 7 if V880527  == 729
replace religfine = 7 if V880527  == 790
replace religfine = 9 if V880527  == 998
replace religfine = 9 if V880527  == 0
replace religfine = . if V880527  == 999

gen religserv =  V880530
replace religserv = . if  V880530 == 9
replace religserv = . if  V880530 == 0

gen religpray =  V880935
replace religpray = . if  V880935 == 9
replace religpray = . if  V880935 == 8
replace religpray = . if  V880935 == 0 
 
gen religimp =  V880932
replace religimp = . if  V880932 == 9
replace religimp = . if  V880932 == 0
replace religimp = . if  V880932 == 8
replace religimp = 0 if  V880932 == 5

keep year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
saveold "Newmerge1988.dta", replace


** 1992 - complete

use NES1992.dta, clear
gen year=1992
gen crosssection = 1 if V923005==2

gen weight = V923008
sum weight
*replace weight = weight/(r(sum)/r(N))

gen pastvote = .
replace pastvote = 0 if V900166==5
replace pastvote = 1 if V900167==2
replace pastvote = 2 if V900167==1
replace pastvote = 3 if V900167==5
replace pastvote = 0 if V923107==5 & pastvote==.
replace pastvote = 1 if V923108==2 & pastvote==.
replace pastvote = 2 if V923108==1 & pastvote==.
replace pastvote = 3 if V923108==5 & pastvote==.

gen currentvote = .
replace currentvote = 0 if V925601==5
replace currentvote = 0 if V925605==2
replace currentvote = 0 if V925608==5
replace currentvote = 1 if V925609==2
replace currentvote = 2 if V925609==1
replace currentvote = 3 if V925609==3
replace currentvote = 3 if V925609==7

gen undecided = 0 
replace undecided = . if V923805 == 9
replace undecided = . if V923805 == 0
replace undecided = 1 if V923805 == 8
replace undecided = 0 if V923807 >= 1 & V923807 <= 7
replace undecided = . if V923807 == 9
replace undecided = 1 if V923807 == 8

** Issue voting
* Gov spend/services V923701-3
gen haveopinion1 = 0 if V923701<9
replace haveopinion1 = 1 if V923701>=1 & V923701<=7
gen seediff1 = 0 if haveopinion1 ==0
replace seediff1 = 0 if V923702==8
replace seediff1 = 0 if V923703==8
replace seediff1 = 0 if V923702==V923703 & V923702<=8 & V923703<=8
replace seediff1 = 1 if 1<=V923702 & V923702<=7 & 1<=V923703 & V923703<=7 & V923702!=V923703
replace seediff1 = . if V923702==9
replace seediff1 = . if V923703==9
replace seediff1 = . if haveopinion1==. 

* Defense spending V923707-9
gen haveopinion2 = 0 if V923701<9
replace haveopinion2 = 1 if V923701>=1 & V923701<=7
gen seediff2 = 0 if haveopinion2 ==0
replace seediff2 = 0 if V923708==8
replace seediff2 = 0 if V923709==8
replace seediff2 = 0 if V923708==V923709 & V923708<=8 & V923709<=8
replace seediff2 = 1 if 1<=V923708 & V923708<=7 & 1<=V923709 & V923709<=7 & V923708!=V923709
replace seediff2 = . if V923708==9
replace seediff2 = . if V923709==9
replace seediff2 = . if haveopinion2==. 

* Job/Std. Living V923718
gen haveopinion3 = 0 if V923718<9
replace haveopinion3 = 1 if V923718>=1 & V923718<=7
gen seediff3 = 0 if haveopinion3 ==0
replace seediff3 = 0 if V923719==8
replace seediff3 = 0 if V923720==8
replace seediff3 = 0 if V923719==V923720 & V923719<=8 & V923720<=8
replace seediff3 = 1 if 1<=V923719 & V923719<=7 & 1<=V923720 & V923720<=7 & V923719!=V923720
replace seediff3 = . if V923719==9
replace seediff3 = . if V923720==9
replace seediff3 = . if haveopinion3==. 

** Abortion 92
gen haveopinion4 = 0 if V923732<9
replace haveopinion4 = 1 if V923732>=1 & V923732<=7
gen seediff4 = 0 if haveopinion4 ==0
replace seediff4 = 0 if V923733==8
replace seediff4 = 0 if V923734==8
replace seediff4 = 0 if V923733==V923734 & V923733<=8 & V923734<=8
replace seediff4 = 1 if 1<=V923733 & V923734<=7 & 1<=V923733 & V923734<=7 & V923733!=V923734
replace seediff4 = . if V923733==9
replace seediff4 = . if V923734==9
replace seediff4 = . if haveopinion4==. 

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4
replace issuevote = (issuevote1+issuevote2 +issuevote3)/3 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4)/3 if issuevote==.
replace issuevote = (issuevote1+issuevote3 + issuevote4)/3 if issuevote==.
replace issuevote = (issuevote2 +issuevote3 + issuevote4)/3 if issuevote==.

*gen weight=1
set type double
gen id = V923004+19920000

gen religid =  V923830
replace religid = . if  V923830 == 0
replace religid = . if  V923830 == 9 
replace religid = 7 if  V923830 == 4
replace religid = 4 if  V923830 == 3

gen	religfine	=	.				
replace	religfine	=	9	if	V923850	==	0
replace	religfine	=	14	if	V923850	==	20
replace	religfine	=	14	if	V923850	==	30
replace	religfine	=	14	if	V923850	==	40
replace	religfine	=	14	if	V923850	==	99
replace	religfine	=	12	if	V923850	==	100
replace	religfine	=	11	if	V923850	==	110
replace	religfine	=	12	if	V923850	==	120
replace	religfine	=	11	if	V923850	==	121
replace	religfine	=	12	if	V923850	==	124
replace	religfine	=	12	if	V923850	==	125
replace	religfine	=	12	if	V923850	==	126
replace	religfine	=	12	if	V923850	==	127
replace	religfine	=	13	if	V923850	==	129
replace	religfine	=	13	if	V923850	==	130
replace	religfine	=	13	if	V923850	==	131
replace	religfine	=	13	if	V923850	==	132
replace	religfine	=	12	if	V923850	==	135
replace	religfine	=	12	if	V923850	==	147
replace	religfine	=	12	if	V923850	==	148
replace	religfine	=	12	if	V923850	==	149
replace	religfine	=	11	if	V923850	==	150
replace	religfine	=	11	if	V923850	==	160
replace	religfine	=	11	if	V923850	==	161
replace	religfine	=	12	if	V923850	==	162
replace	religfine	=	11	if	V923850	==	165
replace	religfine	=	12	if	V923850	==	167
replace	religfine	=	11	if	V923850	==	168
replace	religfine	=	12	if	V923850	==	180
replace	religfine	=	12	if	V923850	==	181
replace	religfine	=	12	if	V923850	==	182
replace	religfine	=	12	if	V923850	==	183
replace	religfine	=	14	if	V923850	==	184
replace	religfine	=	12	if	V923850	==	185
replace	religfine	=	12	if	V923850	==	186
replace	religfine	=	12	if	V923850	==	199
replace	religfine	=	12	if	V923850	==	200
replace	religfine	=	11	if	V923850	==	220
replace	religfine	=	12	if	V923850	==	221
replace	religfine	=	12	if	V923850	==	222
replace	religfine	=	11	if	V923850	==	229
replace	religfine	=	11	if	V923850	==	230
replace	religfine	=	13	if	V923850	==	231
replace	religfine	=	11	if	V923850	==	233
replace	religfine	=	12	if	V923850	==	240
replace	religfine	=	11	if	V923850	==	249
replace	religfine	=	12	if	V923850	==	250
replace	religfine	=	12	if	V923850	==	251
replace	religfine	=	12	if	V923850	==	253
replace	religfine	=	12	if	V923850	==	254
replace	religfine	=	12	if	V923850	==	255
replace	religfine	=	13	if	V923850	==	256
replace	religfine	=	13	if	V923850	==	257
replace	religfine	=	12	if	V923850	==	258
replace	religfine	=	12	if	V923850	==	260
replace	religfine	=	12	if	V923850	==	261
replace	religfine	=	12	if	V923850	==	267
replace	religfine	=	12	if	V923850	==	268
replace	religfine	=	12	if	V923850	==	269
replace	religfine	=	11	if	V923850	==	270
replace	religfine	=	12	if	V923850	==	271
replace	religfine	=	12	if	V923850	==	276
replace	religfine	=	11	if	V923850	==	279
replace	religfine	=	12	if	V923850	==	280
replace	religfine	=	11	if	V923850	==	281
replace	religfine	=	11	if	V923850	==	282
replace	religfine	=	12	if	V923850	==	289
replace	religfine	=	11	if	V923850	==	290
replace	religfine	=	12	if	V923850	==	291
replace	religfine	=	12	if	V923850	==	292
replace	religfine	=	14	if	V923850	==	300
replace	religfine	=	14	if	V923850	==	301
replace	religfine	=	14	if	V923850	==	303
replace	religfine	=	14	if	V923850	==	304
replace	religfine	=	14	if	V923850	==	305
replace	religfine	=	14	if	V923850	==	306
replace	religfine	=	14	if	V923850	==	309
replace	religfine	=	2	if	V923850	==	400
replace	religfine	=	4	if	V923850	==	500
replace	religfine	=	4	if	V923850	==	501
replace	religfine	=	4	if	V923850	==	502
replace	religfine	=	4	if	V923850	==	503
replace	religfine	=	3	if	V923850	==	700
replace	religfine	=	3	if	V923850	==	701
replace	religfine	=	3	if	V923850	==	702
replace	religfine	=	3	if	V923850	==	705
replace	religfine	=	3	if	V923850	==	708
replace	religfine	=	3	if	V923850	==	719
replace	religfine	=	7	if	V923850	==	720
replace	religfine	=	7	if	V923850	==	721
replace	religfine	=	7	if	V923850	==	722
replace	religfine	=	7	if	V923850	==	723
replace	religfine	=	7	if	V923850	==	724
replace	religfine	=	7	if	V923850	==	790
replace	religfine	=	7	if	V923850	==	997
replace	religfine	=	9	if	V923850	==	998
replace	religfine	=	.	if	V923850	==	999

gen religserv = .
replace religserv = . if  V900524 == 9
replace religserv = . if  V900524 == 0
replace religserv = 5 if  V900524 == 5
replace religserv = . if  V900526 == 0
replace religserv = 1 if  V900526 == 1
replace religserv = 2 if  V900526 == 2
replace religserv = 3 if  V900526 == 3
replace religserv = 4 if  V900526 == 4
replace religserv = 5 if  V900526 == 5
replace religserv = . if  V900526 == 9

gen religpray =  V900513
replace religpray = . if   V900513 == 9
replace religpray = . if   V900513 == 0 
 
gen religimp =  V923820
replace religimp = . if  V923820 == 9
replace religimp = . if  V923820 == 0
replace religimp = . if  V923820 == 8
replace religimp = 0 if  V923820 == 5

keep year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 religid religserv religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 religid religserv religpray religimp religfine
saveold "Newmerge1992.dta", replace


** 1996 - complete

use nes96.dta, clear
gen year=1996
gen weight = V960003
gen preweight = V960005A
gen postweight = V960005B

gen pastvote = .
replace pastvote = 0 if V960203==5
replace pastvote = 1 if V960204==2
replace pastvote = 2 if V960204==1
replace pastvote = 3 if V960204==3
replace pastvote = 3 if V960204==7

gen currentvote = .
replace currentvote = 0 if V961074==5
replace currentvote = 0 if V961081==5
replace currentvote = 1 if V961082==1
replace currentvote = 2 if V961082==2
replace currentvote = 3 if V961082==3
replace currentvote = 3 if V961082==7

gen undecided = 0 
replace undecided = . if V960548 == 9
replace undecided = . if V960548 == 0
replace undecided = 1 if V960548 == 5
replace undecided = 1 if V960548 == 8
replace undecided = 0 if V960550 >= 1 & V960550 <= 4
replace undecided = 1 if V960550 == 5
replace undecided = 0 if V960550 == 7
replace undecided = . if V960550 == 9
replace undecided = 1 if V960550 == 8

** Issues 96,
* abortion 5
tab V960503 [iw=weight]
* Women's Role  54.3+8=62
tab V960543 [iw=weight]
* Crime 56+12.6=68.6
tab V960519 [iw=weight]
* Job/Std. living 148.7+4=152.7
tab V960483 [iw=weight]
** aid to Blacks 127 + 9.7 137
tab V960487 [iw=weight]

* Defense spending 214+2.6 = 216.6
tab V960463 [iw=weight]
* Gov services V960450  237.2+7=244
tab V960450  [iw=weight]
* health insurance 165+10.5=175.5
tab V960479   [iw=weight]
* Jobs/environ 228.2+4.9=233.1
tab V960523 [iw=weight]
* Bus. reg/environ 313.1+6.9=320
tab V960537 [iw=weight]
 
* abortion 
tab V960503 [iw=weight]
gen haveopinion1 = 0 if V960503<9
replace haveopinion1 = 1 if V960503<8
gen seediff1 = 0 if haveopinion1 ==0
replace seediff1 = 0 if V960506==8
replace seediff1 = 0 if V960509==8
replace seediff1 = 0 if V960506==V960509 & V960506<=8 & V960509<=8
replace seediff1 = 1 if 1<=V960506 & V960506<=7 & 1<=V960509 & V960509<=7 & V960506!=V960509
replace seediff1 = . if V960506==9
replace seediff1 = . if V960509==9
replace seediff1 = . if haveopinion1==. 

* Women's Role 
*tab V960543 [iw=weight]
*gen haveopinion2 = 0 if V960543<9
*replace haveopinion2 = 1 if V960543>=1 & V960543<=7
*gen seediff2 = 0 if V960544==8
*replace seediff2 = 0 if V960545==8
*replace seediff2 = 0 if V960544==V960545 & V960544<=8 & V960545<=8
*replace seediff2 = 1 if 1<=V960544 & V960544<=7 & 1<=V960545 & V960545<=7 & V960544!=V960545
*replace seediff2 = . if V960544==9
*replace seediff2 = . if V960545==9
*replace seediff2 = . if haveopinion2==. 
*replace seediff2 = 0 if haveopinion2==0 

* def spending
tab V960463 [iw=weight]
gen haveopinion2 = 0 if V960463<9
replace haveopinion2 = 1 if V960463>=1 & V960463<=7
gen seediff2 = 0 if V960464==8
replace seediff2 = 0 if V960465==8
replace seediff2 = 0 if V960464==V960465 & V960464<=8 & V960465<=8
replace seediff2 = 1 if 1<=V960464 & V960464<=7 & 1<=V960465 & V960465<=7 & V960464!=V960465
replace seediff2 = . if V960464==9
replace seediff2 = . if V960465==9
replace seediff2 = . if haveopinion2==. 
replace seediff2 = 0 if haveopinion2==0 

* Crime 
tab V960519 [iw=weight]
gen haveopinion3 = 0 if V960519<9
replace haveopinion3 = 1 if V960519>=1 & V960519<=7
gen seediff3 = 0 if V960520==8
replace seediff3 = 0 if V960521==8
replace seediff3 = 0 if V960520==V960521 & V960520<=8 & V960521<=8
replace seediff3 = 1 if 1<=V960520 & V960520<=7 & 1<=V960521 & V960521<=7 & V960520!=V960521
replace seediff3 = . if V960520==9
replace seediff3 = . if V960521==9
replace seediff3 = . if haveopinion3==. 
replace seediff3 = 0 if haveopinion3==0 

* Job/Std. living 47
tab V960483 [iw=weight]
gen haveopinion4 = 0 if V960483<9
replace haveopinion4 = 1 if V960483>=1 & V960483<=7
gen seediff4 = 0 if V960484==8
replace seediff4 = 0 if V960485==8
replace seediff4 = 0 if V960484==V960485 & V960484<=8 & V960485<=8
replace seediff4 = 1 if 1<=V960484 & V960484<=7 & 1<=V960485 & V960485<=7 & V960484!=V960485
replace seediff4 = . if V960484==9
replace seediff4 = . if V960485==9
replace seediff4 = . if haveopinion4==. 
replace seediff4 = 0 if haveopinion4==0 

** aid to Blacks 48
tab V960487 [iw=weight]
gen haveopinion5 = 0 if V960487<9
replace haveopinion5 = 1 if V960487>=1 & V960487<=7
gen seediff5 = 0 if V960490==8
replace seediff5 = 0 if V960492==8
replace seediff5 = 0 if V960490==V960492 & V960490<=8 & V960492<=8
replace seediff5 = 1 if 1<=V960490 & V960490<=7 & 1<=V960492 & V960492<=7 & V960490!=V960492
replace seediff5 = . if V960490==9
replace seediff5 = . if V960492==9
replace seediff5 = . if haveopinion5==. 
replace seediff5 = 0 if haveopinion5==0 

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

set type double
gen id = V960001+19960000

gen religid = .
replace religid = 1 if V960581 == 1
replace religid = 1 if V960582 == 1
replace religid = 2 if V960581 == 2
replace religid = 2 if V960582 == 2
replace religid = 4 if V960581 == 3
replace religid = 4 if V960582 == 3
replace religid = 7 if V960581 == 7 
replace religid = 7 if V960582 == 7
replace religid = 9 if V960576 == 5 & V960577 == 5

gen religserv = .
replace religserv = 1 if V960578 == 1
replace religserv = 2 if V960578 == 2
replace religserv = 3 if V960578 == 3
replace religserv = 4 if V960578 == 4
replace religserv = 5 if V960578 == 5
replace religserv = . if V960578 == 8
replace religserv = . if V960578 == 0
replace religserv = 5 if V960576 == 5
replace religserv = . if V960576 == 8
replace religserv = . if V960576 == 9

gen religpray =  V960573
replace religpray = . if   V960573 == 9
replace religpray = . if   V960573 == 8 
 
gen religimp = V960571
replace religimp = . if V960571 == 9
replace religimp = . if V960571 == 8
replace religimp = 0 if V960571 == 2

gen religfine = .
replace religfine = 9 if V960602 == 0
replace religfine = 14 if V960602 == 20
replace religfine = 14 if V960602 == 30  
replace religfine = 14 if V960602 == 40  
replace religfine = 14 if V960602 == 99  
replace religfine = 12 if V960602 == 100  
replace religfine = 11 if V960602 == 110  
replace religfine = 12 if V960602 == 120  
replace religfine = 11 if V960602 == 121  
replace religfine = 13 if V960602 == 129  
replace religfine = 12 if V960602 == 135  
replace religfine = 12 if V960602 == 148  
replace religfine = 12 if V960602 == 149  
replace religfine = 11 if V960602 == 150  
replace religfine = 11 if V960602 == 161  
replace religfine = 12 if V960602 == 162  
replace religfine = 11 if V960602 == 165  
replace religfine = 12 if V960602 == 167  
replace religfine = 12 if V960602 == 180  
replace religfine = 12 if V960602 == 181  
replace religfine = 12 if V960602 == 182  
replace religfine = 12 if V960602 == 185  
replace religfine = 12 if V960602 == 186  
replace religfine = 12 if V960602 == 199  
replace religfine = 12 if V960602 == 200  
replace religfine = 11 if V960602 == 220  
replace religfine = 12 if V960602 == 221  
replace religfine = 11 if V960602 == 229  
replace religfine = 11 if V960602 == 230  
replace religfine = 13 if V960602 == 231  
replace religfine = 12 if V960602 == 240  
replace religfine = 11 if V960602 == 249  
replace religfine = 12 if V960602 == 250  
replace religfine = 12 if V960602 == 251  
replace religfine = 12 if V960602 == 253  
replace religfine = 12 if V960602 == 254  
replace religfine = 12 if V960602 == 255  
replace religfine = 13 if V960602 == 256  
replace religfine = 13 if V960602 == 257  
replace religfine = 12 if V960602 == 258  
replace religfine = 12 if V960602 == 260  
replace religfine = 12 if V960602 == 267  
replace religfine = 12 if V960602 == 268  
replace religfine = 12 if V960602 == 269  
replace religfine = 11 if V960602 == 270  
replace religfine = 12 if V960602 == 276  
replace religfine = 11 if V960602 == 279  
replace religfine = 12 if V960602 == 280  
replace religfine = 11 if V960602 == 281  
replace religfine = 11 if V960602 == 290  
replace religfine = 12 if V960602 == 292  
replace religfine = 14 if V960602 == 300  
replace religfine = 14 if V960602 == 301  
replace religfine = 14 if V960602 == 303  
replace religfine = 14 if V960602 == 304  
replace religfine = 2 if V960602 == 400  
replace religfine = 4 if V960602 == 500  
replace religfine = 4 if V960602 == 501  
replace religfine = 4 if V960602 == 502  
replace religfine = 4 if V960602 == 503  
replace religfine = 3 if V960602 == 719  
replace religfine = 7 if V960602 == 720  
replace religfine = 7 if V960602 == 721  
replace religfine = 7 if V960602 == 722  
replace religfine = 7 if V960602 == 723  
replace religfine = 7 if V960602 == 724  
replace religfine = 7 if V960602 == 997
replace religfine = 9 if V960602 == 998
replace religfine = . if V960602 == 999

keep year id preweight postweight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
order year id preweight postweight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
saveold "Newmerge1996.dta", replace


*** 2000 - complete

use anes2000TS.dta, clear

gen year=2000
gen preweight = V000002
gen postweight = V000002a
gen weight = postweight

gen pastvote = .
replace pastvote = 0 if V000303==5
replace pastvote = 1 if V000304==1
replace pastvote = 2 if V000304==3
replace pastvote = 3 if V000304==5
replace pastvote = 3 if V000304==7

gen currentvote = .
replace currentvote = 0 if V001241==1
replace currentvote = 0 if V001241==2
replace currentvote = 0 if V001241==3
replace currentvote = 0 if V001248==5
replace currentvote = 1 if V001249==1
replace currentvote = 2 if V001249==3
replace currentvote = 3 if V001249==5
replace currentvote = 3 if V001249==6
replace currentvote = 3 if V001249==2
replace currentvote = 3 if V001249==4

replace weight=preweight

gen partisan = 0 if V000523<8
replace partisan = 1 if V000523==0
replace partisan = 1 if V000523==1
replace partisan = 1 if V000523==5
replace partisan = 1 if V000523==6
gen macro = 0 if partisan==1
replace macro = 1 if V000523==0
replace macro = 1 if V000523==1
tab partisan
tab partisan [iw=weight]
tab macro [iw=weight]

gen pidstrength = 0 if V000523==3
replace pidstrength = 0 if V000523==8
replace pidstrength = 1 if V000523==2
replace pidstrength = 1 if V000523==4
replace pidstrength = 1 if V000523==1
replace pidstrength = 1 if V000523==5
replace pidstrength = 2 if V000523==0
replace pidstrength = 2 if V000523==6
tab pidstrength V000523

gen undecided = 0 
replace undecided = . if V000793 == 9
replace undecided = . if V000793 == 0
replace undecided = 1 if V000793 == 5
replace undecided = 1 if V000793 == 8
replace undecided = 0 if V000795 >= 1 & V000795 <= 4
replace undecided = 1 if V000795 == 5
replace undecided = 0 if V000795 == 7
replace undecided = 1 if V000795 == 8
replace undecided = . if V000795 == 9

* Abortion 12.3
tab V000694 [iw=weight]
gen haveopinion1 = 0 if V000694>0 &  V000694<=8
replace haveopinion1 = 1 if V000694>=1 & V000694<=7
gen seediff1 = 0 if haveopinion1==0
replace seediff1 = 0 if V000696==8
replace seediff1 = 0 if V000698==8
replace seediff1 = . if V000696==9
replace seediff1 = . if V000698==9
replace seediff1 = . if V000696==0
replace seediff1 = . if V000698==9
replace seediff1 = 0 if V000696==V000698 & V000696>=1 & V000696<=7  & V000698>=1 & V000698<=7
replace seediff1 = 1 if V000696!=V000698 & V000696>=1 & V000696<=7  & V000698>=1 & V000698<=7
replace seediff1 = 0 if haveopinion1==0
tab seediff1 haveopinion1

* Women Equal Role 44.5 + 5.3
*tab V000760 [iw=weight]
*gen haveopinion2 = 0 if V000760==0
*replace haveopinion2 = 0 if V000760==8
*replace haveopinion2 = 1 if V000760>=1 & V000760<=5
*gen seediff2 = 0 if haveopinion2==0
*replace seediff2 = 0 if V000761==8
*replace seediff2 = 0 if V000764==8
*replace seediff2 = . if V000714==9
*replace seediff2 = . if V000717==9
*replace seediff2 = 0 if V000719==8
*replace seediff2 = 0 if V000722==8
*replace seediff2 = . if V000719==9
*replace seediff2 = . if V000722==9
*replace seediff2 = 0 if V000714==V000719 & V000714>=1 & V000714<=7  & V000719>=1 & V000719<=7
*replace seediff2 = 1 if V000714!=V000719 & V000714>=1 & V000714<=7  & V000719>=1 & V000719<=7
*replace seediff2 = 0 if V000717==V000722 & V000717>=1 & V000717<=5  & V000722>=1 & V000722<=5
*replace seediff2 = 1 if V000717!=V000722 & V000717>=1 & V000717<=5  & V000722>=1 & V000722<=5
*replace seediff2 = 0 if haveopinion2==0
*tab seediff2 haveopinion2

* Gov Jobs/Std Living, 228.2+8.4 = 236.6
tab V000620 [iw=weight]
gen haveopinion3 = 0 if V000620==0
replace haveopinion3 = 0 if V000620==8
replace haveopinion3 = 1 if V000620>=1 & V000620<=5
tab haveopinion3 V000620 [iw=weight], col

gen seediff3 = 0 if haveopinion3==0
replace seediff3 = 0 if V000621==8
replace seediff3 = 0 if V000624==8
replace seediff3 = . if V000621==9
replace seediff3 = . if V000624==9
replace seediff3 = 0 if V000626==8
replace seediff3 = 0 if V000629==8
replace seediff3 = . if V000626==9
replace seediff3 = . if V000629==9
replace seediff3 = 0 if V000621==V000626 & V000621>=1 & V000621<=7  & V000626>=1 & V000626<=7
replace seediff3 = 1 if V000621!=V000626 & V000621>=1 & V000621<=7  & V000626>=1 & V000626<=7
replace seediff3 = 0 if V000624==V000629 & V000624>=1 & V000624<=5  & V000629>=1 & V000629<=5
replace seediff3 = 1 if V000624!=V000629 & V000624>=1 & V000624<=5  & V000629>=1 & V000629<=5
replace seediff3 = 0 if haveopinion3==0

* Aid to blacks, 256.7+6.1=262.8
tab V000645 [iw=weight]
gen haveopinion4 = 0 if V000645==0
replace haveopinion4 = 0 if V000645==8
replace haveopinion4 = 1 if V000645>=1 & V000645<=5
tab haveopinion4 V000645 [iw=weight], col

gen seediff4 = 0 if haveopinion4==0
replace seediff4 = 0 if V000651==8
replace seediff4 = 0 if V000654==8
replace seediff4 = . if V000651==9
replace seediff4 = . if V000654==9
replace seediff4 = 0 if V000656==8
replace seediff4 = 0 if V000659==8
replace seediff4 = . if V000656==9
replace seediff4 = . if V000659==9
replace seediff4 = 0 if V000651==V000656 & V000651>=1 & V000651<=7  & V000656>=1 & V000656<=7
replace seediff4 = 1 if V000651!=V000656 & V000651>=1 & V000651<=7  & V000656>=1 & V000656<=7
replace seediff4 = 0 if V000654==V000659 & V000654>=1 & V000654<=5  & V000659>=1 & V000659<=5
replace seediff4 = 1 if V000654!=V000659 & V000654>=1 & V000654<=5  & V000659>=1 & V000659<=5
replace seediff4 = 0 if haveopinion4==0

tab seediff4 haveopinion4
tab V000651 V000656 if seediff4==1
tab V000654 V000659 if seediff4==1

* Jobs/Environ, 193.7+55 = 248.7
tab V000713  [iw=weight]
gen haveopinion5 = 0 if V000713==0
replace haveopinion5 = 0 if V000713==8
replace haveopinion5 = 1 if V000713>=1 & V000713<=5
gen seediff5 = 0 if haveopinion5==0
replace seediff5 = 0 if V000714==8
replace seediff5 = 0 if V000717==8
replace seediff5 = . if V000714==9
replace seediff5 = . if V000717==9
replace seediff5 = 0 if V000719==8
replace seediff5 = 0 if V000722==8
replace seediff5 = . if V000719==9
replace seediff5 = . if V000722==9
replace seediff5 = 0 if V000714==V000719 & V000714>=1 & V000714<=7  & V000719>=1 & V000719<=7
replace seediff5 = 1 if V000714!=V000719 & V000714>=1 & V000714<=7  & V000719>=1 & V000719<=7
replace seediff5 = 0 if V000717==V000722 & V000717>=1 & V000717<=5  & V000722>=1 & V000722<=5
replace seediff5 = 1 if V000717!=V000722 & V000717>=1 & V000717<=5  & V000722>=1 & V000722<=5
replace seediff5 = 0 if haveopinion5==0

* Gov serv/spending 324.3+15.6=339
tab V000550 [iw=weight]
gen haveopinion2 = 0 if V000550==0
replace haveopinion2 = 0 if V000550==8
replace haveopinion2 = 1 if V000550>=1 & V000550<=5
gen seediff2 = 0 if haveopinion1==0
replace seediff2 = 0 if V000557==8
replace seediff2 = 0 if V000561==8
replace seediff2 = . if V000557==9
replace seediff2 = . if V000561==9
replace seediff2 = 0 if V000563==8
replace seediff2 = 0 if V000567==8
replace seediff2 = . if V000563==9
replace seediff2 = . if V000567==9
replace seediff2 = 0 if V000557==V000563 & V000557>=1 & V000557<=7  & V000563>=1 & V000563<=7
replace seediff2 = 1 if V000557!=V000563 & V000557>=1 & V000557<=7  & V000563>=1 & V000563<=7
replace seediff2 = 0 if V000561==V000567 & V000561>=1 & V000561<=5  & V000567>=1 & V000567<=5
replace seediff2 = 1 if V000561!=V000567 & V000561>=1 & V000561<=5  & V000567>=1 & V000567<=5
replace seediff2 = 0 if haveopinion1==0
*tab seediff1 haveopinion1

* Def. Spending 424.7+13.8 = 438.5
tab V000587 [iw=weight]
*gen haveopinion12 = 0 if V000587==0
*replace haveopinion12 = 0 if V000587==8
*replace haveopinion12 = 1 if V000587>=1 & V000587<=5
*tab haveopinion12 V000587 [iw=weight], col
*gen seediff12 = 0 if haveopinion12==0
*replace seediff12 = 0 if V000588==8
*replace seediff12 = 0 if V000591==8
*replace seediff12 = . if V000588==9
*replace seediff12 = . if V000591==9
*replace seediff12 = 0 if V000593==8
*replace seediff12 = 0 if V000596==8
*replace seediff12 = . if V000593==9
*replace seediff12 = . if V000596==9
*replace seediff12 = 0 if V000588==V000593 & V000588>=1 & V000588<=7  & V000593>=1 & V000593<=7
*replace seediff12 = 1 if V000588!=V000593 & V000588>=1 & V000588<=7  & V000593>=1 & V000593<=7
*replace seediff12 = 0 if V000591==V000596 & V000591>=1 & V000591<=5  & V000596>=1 & V000596<=5
*replace seediff12 = 1 if V000591!=V000596 & V000591>=1 & V000591<=5  & V000596>=1 & V000596<=5
*replace seediff12 = 0 if haveopinion12==0
*tab seediff12 haveopinion12
*tab V000588 V000593 if seediff12==1
*tab V000591 V000596 if seediff12==1

* Enviro Regulations, 498+14.5=512.5
tab V000776  [iw=weight]
*gen haveopinion17 = 0 if V000776==0
*replace haveopinion17 = 0 if V000776==8
*replace haveopinion17 = 1 if V000776>=1 & V000776<=5
*tab haveopinion17 V000776 [iw=weight], col
*gen seediff17 = 0 if haveopinion17==0
*replace seediff17 = 0 if V000778==8
*replace seediff17 = 0 if V000782==8
*replace seediff17 = . if V000778==9
*replace seediff17 = . if V000782==9
*replace seediff17 = 0 if V000785==8
*replace seediff17 = 0 if V000789==8
*replace seediff17 = . if V000785==9
*replace seediff17 = . if V000789==9
*replace seediff17 = 0 if V000778==V000785 & V000778>=1 & V000778<=7  & V000785>=1 & V000785<=7
*replace seediff17 = 1 if V000778!=V000785 & V000778>=1 & V000778<=7  & V000785>=1 & V000785<=7
*replace seediff17 = 0 if V000782==V000789 & V000782>=1 & V000782<=5  & V000789>=1 & V000789<=5
*replace seediff17 = 1 if V000782!=V000789 & V000782>=1 & V000782<=5  & V000789>=1 & V000789<=5
*replace seediff17 = 0 if haveopinion17==0
*tab seediff17 haveopinion17

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

set type double
gen id = V000001+20000000

gen religid = .
replace religid = . if V000882 == 8 
replace religid = . if V000882 == 9 
replace religid = . if V000883 == 8
replace religid = . if V000883 == 9 
replace religid = 1 if V000882 == 1
replace religid = 1 if V000883 == 1
replace religid = 2 if V000882 == 2
replace religid = 2 if V000883 == 2
replace religid = 4 if V000882 == 3
replace religid = 4 if V000883 == 3
replace religid = 7 if V000882 == 7 
replace religid = 7 if V000883 == 7
replace religid = 9 if V000877 == 5 & V000878 == 5

gen	religfine	=	.				
replace	religfine	=	9	if	V000904	==	0
replace	religfine	=	14	if	V000904	==	10
replace	religfine	=	14	if	V000904	==	20
replace	religfine	=	14	if	V000904	==	30
replace	religfine	=	14	if	V000904	==	40
replace	religfine	=	14	if	V000904	==	99
replace	religfine	=	12	if	V000904	==	100
replace	religfine	=	11	if	V000904	==	110
replace	religfine	=	12	if	V000904	==	120
replace	religfine	=	11	if	V000904	==	121
replace	religfine	=	12	if	V000904	==	124
replace	religfine	=	12	if	V000904	==	125
replace	religfine	=	12	if	V000904	==	127
replace	religfine	=	13	if	V000904	==	129
replace	religfine	=	12	if	V000904	==	135
replace	religfine	=	12	if	V000904	==	147
replace	religfine	=	12	if	V000904	==	148
replace	religfine	=	12	if	V000904	==	149
replace	religfine	=	11	if	V000904	==	150
replace	religfine	=	11	if	V000904	==	160
replace	religfine	=	11	if	V000904	==	161
replace	religfine	=	12	if	V000904	==	162
replace	religfine	=	12	if	V000904	==	164
replace	religfine	=	11	if	V000904	==	165
replace	religfine	=	12	if	V000904	==	166
replace	religfine	=	12	if	V000904	==	167
replace	religfine	=	12	if	V000904	==	180
replace	religfine	=	12	if	V000904	==	181
replace	religfine	=	12	if	V000904	==	182
replace	religfine	=	14	if	V000904	==	184
replace	religfine	=	12	if	V000904	==	185
replace	religfine	=	12	if	V000904	==	186
replace	religfine	=	12	if	V000904	==	199
replace	religfine	=	12	if	V000904	==	200
replace	religfine	=	11	if	V000904	==	220
replace	religfine	=	12	if	V000904	==	221
replace	religfine	=	12	if	V000904	==	222
replace	religfine	=	11	if	V000904	==	229
replace	religfine	=	11	if	V000904	==	230
replace	religfine	=	13	if	V000904	==	231
replace	religfine	=	12	if	V000904	==	240
replace	religfine	=	11	if	V000904	==	249
replace	religfine	=	12	if	V000904	==	250
replace	religfine	=	12	if	V000904	==	251
replace	religfine	=	12	if	V000904	==	253
replace	religfine	=	12	if	V000904	==	254
replace	religfine	=	12	if	V000904	==	255
replace	religfine	=	13	if	V000904	==	256
replace	religfine	=	13	if	V000904	==	257
replace	religfine	=	12	if	V000904	==	258
replace	religfine	=	12	if	V000904	==	260
replace	religfine	=	12	if	V000904	==	264
replace	religfine	=	12	if	V000904	==	267
replace	religfine	=	12	if	V000904	==	268
replace	religfine	=	12	if	V000904	==	269
replace	religfine	=	11	if	V000904	==	270
replace	religfine	=	12	if	V000904	==	272
replace	religfine	=	12	if	V000904	==	275
replace	religfine	=	12	if	V000904	==	276
replace	religfine	=	11	if	V000904	==	279
replace	religfine	=	12	if	V000904	==	280
replace	religfine	=	11	if	V000904	==	281
replace	religfine	=	11	if	V000904	==	290
replace	religfine	=	12	if	V000904	==	292
replace	religfine	=	14	if	V000904	==	300
replace	religfine	=	14	if	V000904	==	301
replace	religfine	=	14	if	V000904	==	303
replace	religfine	=	14	if	V000904	==	304
replace	religfine	=	2	if	V000904	==	400
replace	religfine	=	4	if	V000904	==	500
replace	religfine	=	4	if	V000904	==	501
replace	religfine	=	4	if	V000904	==	502
replace	religfine	=	4	if	V000904	==	503
replace	religfine	=	14	if	V000904	==	600
replace	religfine	=	3	if	V000904	==	700
replace	religfine	=	3	if	V000904	==	701
replace	religfine	=	3	if	V000904	==	719
replace	religfine	=	7	if	V000904	==	720
replace	religfine	=	7	if	V000904	==	721
replace	religfine	=	7	if	V000904	==	722
replace	religfine	=	7	if	V000904	==	723
replace	religfine	=	7	if	V000904	==	724
replace	religfine	=	7	if	V000904	==	727
replace	religfine	=	7	if	V000904	==	750
replace	religfine	=	7	if	V000904	==	795
replace	religfine	=	8	if	V000904	==	800
replace	religfine	=	9	if	V000904	==	990
replace	religfine	=	.	if	V000904	==	995
replace	religfine	=	7	if	V000904	==	997
replace	religfine	=	9	if	V000904	==	998
replace	religfine	=	.	if	V000904	==	999

gen religserv = .
replace religserv = 1 if V000879 == 1
replace religserv = 2 if V000879 == 2
replace religserv = 3 if V000879 == 3
replace religserv = 4 if V000879 == 4
replace religserv = 5 if V000879 == 5
replace religserv = . if V000879 == 8
replace religserv = . if V000879 == 9
replace religserv = . if V000879 == 0
replace religserv = 5 if V000877 == 5
replace religserv = . if V000877 == 9
replace religserv = . if V000877 == 0

gen religpray =  V000874
replace religpray = . if  V000874 == 0
replace religpray = . if  V000874 == 7
replace religpray = . if  V000874 == 9
replace religpray = . if  V000874 == 8 
 
gen religimp = V000872
replace religimp = . if V000872 == 9
replace religimp = . if V000872 == 8
replace religimp = 0 if V000872 == 5

keep year id preweight postweight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
order year id preweight postweight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
saveold "Newmerge2000.dta", replace

**2004 - complete

use anes2004.dta, clear
gen year=2004
gen preweight = V040101
gen postweight = V040102

gen pastvote = .
replace pastvote = 0 if V043002==5
replace pastvote = 1 if V043003==1
replace pastvote = 2 if V043003==3
replace pastvote = 3 if V043003==5
replace pastvote = 3 if V043003==6
replace pastvote = 3 if V043003==7

gen currentvote = .
replace currentvote = 0 if V045018x==2
replace currentvote = 0 if V045018x==3
replace currentvote = 0 if V045018x==4
replace currentvote = 0 if V045018x==5
replace currentvote = 0 if V045025==5
replace currentvote = 1 if V045026==1
replace currentvote = 2 if V045026==3
replace currentvote = 3 if V045026==5
replace currentvote = 3 if V045026==7

gen undecided = 0 
replace undecided = . if V043203 == 9
replace undecided = . if V043203 == 0
replace undecided = 1 if V043203 == 5
replace undecided = 1 if V043203 == 8

gen weight = preweight

** Issue voting scale
* hand guns V043188, 10
* womens role, V043196 49 + 6 = 55
* job standard of living, V043152, 105+4 = 109
* assistance to blacks, V043158, 111+11 = 122
* Def spending V043142, 146+5 = 151
*tab V043142 [iw=weight]
* Gov spending, V043136, 149+3 = 152
*tab V043136 [iw=weight]
* Interventionism, V043107, 161 + 7 = 168, no bush kerry
* Medical care V043150, 92+7 = 99, no bush kerry
* enviro jobs, V043182, 184+5 = 189

* Handguns 
tab V043188 [iw=weight]
gen haveopinion1 = 0 if V043188>0 &  V043188<=8
replace haveopinion1 = 1 if V043188>=1 & V043188<=7
tab V043192 V043191
gen seediff1 = 0 if haveopinion1==0
replace seediff1 = 0 if V043191==8
replace seediff1 = 0 if V043193==8
replace seediff1 = . if V043191==9
replace seediff1 = . if V043193==9
replace seediff1 = 0 if V043192==V043194 & V043192>=1 & V043192<=7  & V043194>=1 & V043194<=7
replace seediff1 = 1 if V043192!=V043194 & V043192>=1 & V043192<=7  & V043194>=1 & V043194<=7
replace seediff1 = 0 if haveopinion1==0
replace haveopinion1=0 if seediff1==0 & haveopinion1==.
tab seediff1 haveopinion1

* Women Equal Role 
tab V043196 [iw=weight]
gen haveopinion2 = 0 if V043196==80
replace haveopinion2 = 0 if V043196==88
replace haveopinion2 = 1 if V043196>=1 & V043196<=7
gen seediff2 = 0 if haveopinion2==0
replace seediff2 = 0 if V043198==8
replace seediff2 = 0 if V043199==8
replace seediff2 = . if V043198==9
replace seediff2 = . if V043199==9
replace seediff2 = 0 if V043198==V043199 & V043198>=1 & V043198<=7  & V043199>=1 & V043199<=7
replace seediff2 = 1 if V043198!=V043199 & V043198>=1 & V043198<=7  & V043199>=1 & V043199<=7
replace seediff2 = 0 if haveopinion2==0
replace haveopinion2=0 if seediff2==0 & haveopinion2==.
tab seediff2 haveopinion2

* Gov Jobs/Std Living, 
tab V043152 [iw=weight]
gen haveopinion3 = 0 if V043152==80
replace haveopinion3 = 0 if V043152==88
replace haveopinion3 = 1 if V043152>=1 & V043152<=7
tab haveopinion3 V043152 [iw=weight], col

gen seediff3 = 0 if haveopinion3==0
replace seediff3 = 0 if V043154==8
replace seediff3 = 0 if V043155==8
replace seediff3 = . if V043154==9
replace seediff3 = . if V043155==9
replace seediff3 = 0 if V043154==V043155 & V043154>=1 & V043154<=7  & V043155>=1 & V043155<=7
replace seediff3 = 1 if V043154!=V043155 & V043154>=1 & V043154<=7  & V043155>=1 & V043155<=7
replace seediff3 = 0 if haveopinion3==0
replace haveopinion3=0 if seediff3==0 & haveopinion3==.
tab seediff3 haveopinion3, col

* Aid to blacks,
tab V043158 [iw=weight]
gen haveopinion4 = 0 if V043158==80
replace haveopinion4 = 0 if V043158==88
replace haveopinion4 = 1 if V043158>=1 & V043158<=7
tab haveopinion4 V043158 [iw=weight], col

gen seediff4 = 0 if haveopinion4==0
replace seediff4 = 0 if V043160==8
replace seediff4 = 0 if V043161==8
replace seediff4 = . if V043160==9
replace seediff4 = . if V043161==9
replace seediff4 = 0 if V043160==V043161 & V043160>=1 & V043160<=7  & V043161>=1 & V043161<=7
replace seediff4 = 1 if V043160!=V043161 & V043160>=1 & V043160<=7  & V043161>=1 & V043161<=7
replace seediff4 = 0 if haveopinion4==0
replace haveopinion4=0 if seediff4==0 & haveopinion4==.
tab seediff4 haveopinion4

* Defense spending,
tab V043142  [iw=weight]
gen haveopinion5 = 0 if V043142==80
replace haveopinion5 = 0 if V043142==88
replace haveopinion5 = 1 if V043142>=1 & V043142<=7
tab haveopinion5 V043142 [iw=weight], col

gen seediff5 = 0 if haveopinion5==0
replace seediff5 = 0 if V043144==8
replace seediff5 = 0 if V043145==8
replace seediff5 = . if V043144==9
replace seediff5 = . if V043145==9
replace seediff5 = 0 if V043144==V043145 & V043144>=1 & V043144<=7  & V043145>=1 & V043145<=7
replace seediff5 = 1 if V043144!=V043145 & V043144>=1 & V043144<=7  & V043145>=1 & V043145<=7
replace seediff5 = 0 if haveopinion5==0

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

set type double
gen id = V040001+20040000

gen religid = V043247
replace religid = . if V043247 == 9
replace religid = . if V043247 == 8
replace religid = . if V043247 == 0
replace religid = 7 if V043247 == 6
replace religid = 9 if V043247 == 7

gen religserv = .
replace religserv = 1 if  V043224 == 1
replace religserv = 2 if  V043224 == 2
replace religserv = 3 if  V043224 == 3
replace religserv = 4 if  V043224 == 4
replace religserv = 5 if  V043224 == 5
replace religserv = . if  V043224 == 8
replace religserv = . if  V043224 == 9
replace religserv = 5 if V043223 == 5
replace religserv = . if V043223 == 9
replace religserv = . if V043223 == 8

gen religpray = V043221
replace religpray = . if V043221 == 7
replace religpray = . if V043221 == 9
replace religpray = . if V043221 == 8 
 
gen religimp = V043219
replace religimp = . if V043219 == 9
replace religimp = . if V043219 == 8
replace religimp = 0 if V043219 == 5

gen	religfine	=	.				
replace	religfine	=	.	if	V043248	==	0
replace	religfine	=	14	if	V043248	==	20
replace	religfine	=	14	if	V043248	==	30
replace	religfine	=	14	if	V043248	==	40
replace	religfine	=	14	if	V043248	==	99
replace	religfine	=	12	if	V043248	==	100
replace	religfine	=	11	if	V043248	==	110
replace	religfine	=	12	if	V043248	==	120
replace	religfine	=	11	if	V043248	==	121
replace	religfine	=	12	if	V043248	==	124
replace	religfine	=	12	if	V043248	==	125
replace	religfine	=	12	if	V043248	==	126
replace	religfine	=	12	if	V043248	==	127
replace	religfine	=	13	if	V043248	==	129
replace	religfine	=	13	if	V043248	==	130
replace	religfine	=	13	if	V043248	==	131
replace	religfine	=	13	if	V043248	==	132
replace	religfine	=	12	if	V043248	==	135
replace	religfine	=	12	if	V043248	==	147
replace	religfine	=	12	if	V043248	==	148
replace	religfine	=	12	if	V043248	==	149
replace	religfine	=	11	if	V043248	==	150
replace	religfine	=	11	if	V043248	==	160
replace	religfine	=	11	if	V043248	==	161
replace	religfine	=	12	if	V043248	==	162
replace	religfine	=	12	if	V043248	==	164
replace	religfine	=	11	if	V043248	==	165
replace	religfine	=	12	if	V043248	==	167
replace	religfine	=	11	if	V043248	==	168
replace	religfine	=	12	if	V043248	==	180
replace	religfine	=	12	if	V043248	==	181
replace	religfine	=	12	if	V043248	==	182
replace	religfine	=	12	if	V043248	==	183
replace	religfine	=	14	if	V043248	==	184
replace	religfine	=	12	if	V043248	==	185
replace	religfine	=	12	if	V043248	==	186
replace	religfine	=	12	if	V043248	==	199
replace	religfine	=	12	if	V043248	==	200
replace	religfine	=	11	if	V043248	==	220
replace	religfine	=	12	if	V043248	==	221
replace	religfine	=	12	if	V043248	==	222
replace	religfine	=	11	if	V043248	==	229
replace	religfine	=	11	if	V043248	==	230
replace	religfine	=	13	if	V043248	==	231
replace	religfine	=	11	if	V043248	==	233
replace	religfine	=	12	if	V043248	==	240
replace	religfine	=	11	if	V043248	==	249
replace	religfine	=	12	if	V043248	==	250
replace	religfine	=	12	if	V043248	==	251
replace	religfine	=	12	if	V043248	==	253
replace	religfine	=	12	if	V043248	==	254
replace	religfine	=	12	if	V043248	==	255
replace	religfine	=	13	if	V043248	==	256
replace	religfine	=	13	if	V043248	==	257
replace	religfine	=	12	if	V043248	==	258
replace	religfine	=	12	if	V043248	==	260
replace	religfine	=	12	if	V043248	==	261
replace	religfine	=	12	if	V043248	==	264
replace	religfine	=	12	if	V043248	==	267
replace	religfine	=	12	if	V043248	==	268
replace	religfine	=	12	if	V043248	==	269
replace	religfine	=	11	if	V043248	==	270
replace	religfine	=	12	if	V043248	==	271
replace	religfine	=	12	if	V043248	==	272
replace	religfine	=	12	if	V043248	==	275
replace	religfine	=	12	if	V043248	==	276
replace	religfine	=	11	if	V043248	==	279
replace	religfine	=	12	if	V043248	==	280
replace	religfine	=	11	if	V043248	==	281
replace	religfine	=	11	if	V043248	==	282
replace	religfine	=	12	if	V043248	==	289
replace	religfine	=	11	if	V043248	==	290
replace	religfine	=	12	if	V043248	==	291
replace	religfine	=	12	if	V043248	==	292
replace	religfine	=	14	if	V043248	==	300
replace	religfine	=	14	if	V043248	==	301
replace	religfine	=	14	if	V043248	==	303
replace	religfine	=	14	if	V043248	==	304
replace	religfine	=	14	if	V043248	==	305
replace	religfine	=	14	if	V043248	==	306
replace	religfine	=	14	if	V043248	==	309
replace	religfine	=	2	if	V043248	==	400
replace	religfine	=	4	if	V043248	==	500
replace	religfine	=	4	if	V043248	==	501
replace	religfine	=	4	if	V043248	==	502
replace	religfine	=	4	if	V043248	==	503
replace	religfine	=	4	if	V043248	==	524
replace	religfine	=	7	if	V043248	==	600
replace	religfine	=	3	if	V043248	==	700
replace	religfine	=	3	if	V043248	==	701
replace	religfine	=	3	if	V043248	==	702
replace	religfine	=	3	if	V043248	==	705
replace	religfine	=	3	if	V043248	==	706
replace	religfine	=	3	if	V043248	==	708
replace	religfine	=	3	if	V043248	==	719
replace	religfine	=	7	if	V043248	==	720
replace	religfine	=	7	if	V043248	==	721
replace	religfine	=	7	if	V043248	==	722
replace	religfine	=	7	if	V043248	==	723
replace	religfine	=	7	if	V043248	==	724
replace	religfine	=	7	if	V043248	==	729
replace	religfine	=	7	if	V043248	==	790
replace	religfine	=	7	if	V043248	==	795
replace	religfine	=	9	if	V043248	==	880
replace	religfine	=	8	if	V043248	==	881
replace	religfine	=	8	if	V043248	==	882
replace	religfine	=	7	if	V043248	==	997
replace	religfine	=	9	if	V043248	==	888
replace	religfine	=	.	if	V043248	==	889

keep year id preweight postweight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
order year id preweight postweight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
saveold "Newmerge2004.dta", replace

** 2008- complete

clear
use anes2008.dta, clear
gen year=2008
gen preweight = V080101
gen postweight = V080102

gen pastvote = .
replace pastvote = 0 if V083007==5
replace pastvote = 1 if V083007a==1
replace pastvote = 2 if V083007a==3
replace pastvote = 3 if V083007a==7

gen currentvote = .
replace currentvote = 0 if V085036x==0
replace currentvote = 0 if V085044==5
replace currentvote = 1 if V085044a==1
replace currentvote = 2 if V085044a==3
replace currentvote = 3 if V085044a==7

gen undecided = 0 
replace undecided = . if V083169a == -9
replace undecided = . if V083169a == -1
replace undecided = 1 if V083169a == 5
replace undecided = 1 if V083169a == -8

gen form = V082402

** Issue voting scale
* asked to all
* aids to minorities, V083137, 367
tab V083137
gen haveopinion1 = 0 if V083137>-9 &  V083137<=7
replace haveopinion1 = 1 if V083137>=1 & V083137<=7
gen seediff1 = 0 if haveopinion1==0
replace seediff1 = 0 if V083139a==-8
replace seediff1 = 0 if V083139b==-8
replace seediff1 = . if V083139a==-9
replace seediff1 = . if V083139b==-9
replace seediff1 = 0 if V083139a==V083139b & V083139a>=1 & V083139a<=7  & V083139b>=1 & V083139b<=7
replace seediff1 = 1 if V083139a!=V083139b & V083139a>=1 & V083139a<=7  & V083139b>=1 & V083139b<=7
replace seediff1 = 0 if haveopinion1==0
replace haveopinion1=0 if seediff1==0 & haveopinion1==.
tab seediff1 haveopinion1

* Form Split, with different issue placement items
* new ones are much more policy focused (not broader principles) I stick with old issue placement items

* women's role V083166, 36 = 36
gen haveopinion2 = 0 if form==1 & V083166>-9 & V083166<=7
replace haveopinion2 = 1 if form==1 & V083166>=1 & V083166<=7
gen seediff2= 0 if haveopinion2==0 & form==1
replace seediff2 = 0 if V083168a==-8 & form==1
replace seediff2 = 0 if V083168b==-8 & form==1
replace seediff2 = . if V083168a==-9 & form==1
replace seediff2 = . if V083168b==-9 & form==1
replace seediff2 = 0 if V083168a==V083168b & V083168a>=1 & V083168a<=7  & V083168b>=1 & V083168b<=7 & form==1
replace seediff2 = 1 if V083168a!=V083168b & V083168a>=1 & V083168a<=7  & V083168b>=1 & V083168b<=7 & form==1
replace seediff2 = 0 if haveopinion2==0 & form==1

* gov med insurance V083119, 99+11 = 110
gen haveopinion3= 0 if form==1 & V083119>-9 & V083119<=7
replace haveopinion3 = 1 if form==1 & V083119>=1 & V083119<=7
gen seediff3= 0 if haveopinion3==0 & form==1
replace seediff3 = 0 if V083121a==-8 & form==1
replace seediff3 = 0 if V083121b==-8 & form==1
replace seediff3 = . if V083121a==-9 & form==1
replace seediff3 = . if V083121b==-9 & form==1
replace seediff3 = 0 if V083121a==V083121b & V083121a>=1 & V083121a<=7  & V083121b>=1 & V083121b<=7 & form==1
replace seediff3 = 1 if V083121a!=V083121b & V083121a>=1 & V083121a<=7  & V083121b>=1 & V083121b<=7 & form==1
replace seediff3 = 0 if haveopinion3==0 & form==1

* jobs std living V083128, 120+7 = 127
gen haveopinion4= 0 if form==1 & V083128>-9 & V083128<=7
replace haveopinion4 = 1 if form==1 & V083128>=1 & V083128<=7
gen seediff4= 0 if haveopinion4==0 & form==1
replace seediff4 = 0 if V083130a==-8 & form==1
replace seediff4 = 0 if V083130b==-8 & form==1
replace seediff4 = . if V083130a==-9 & form==1
replace seediff4 = . if V083130b==-9 & form==1
replace seediff4 = 0 if V083130a==V083130b & V083130a>=1 & V083130a<=7  & V083130b>=1 & V083130b<=7 & form==1
replace seediff4 = 1 if V083130a!=V083130b & V083130a>=1 & V083130a<=7  & V083130b>=1 & V083130b<=7 & form==1
replace seediff4 = 0 if haveopinion4==0 & form==1

* def spending V083112 = 180+10 = 190
gen haveopinion5= 0 if form==1 & V083112>-9 & V083112<=7
replace haveopinion5 = 1 if form==1 & V083112>=1 & V083112<=7
gen seediff5= 0 if haveopinion5==0 & form==1
replace seediff5 = 0 if V083114a==-8 & form==1
replace seediff5 = 0 if V083114b==-8 & form==1
replace seediff5 = . if V083114a==-9 & form==1
replace seediff5 = . if V083114b==-9 & form==1
replace seediff5 = 0 if V083114a==V083114b & V083114a>=1 & V083114a<=7  & V083114b>=1 & V083114b<=7 & form==1
replace seediff5 = 1 if V083114a!=V083114b & V083114a>=1 & V083114a<=7  & V083114b>=1 & V083114b<=7 & form==1
replace seediff5 = 0 if haveopinion5==0 & form==1
* gov spending V083105, 194+6 = 200
* enviro jobs tradeoff V083154, 215+13 = 228

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

set type double
gen id = V080001+20080000

gen religid = V083185b
replace religid = . if V083185b == -9
replace religid = . if V083185b == -8
replace religid = . if V083185b == -4
replace religid = . if V083185b == -1
replace religid = 9 if V083185b == 0

gen religserv = .
replace religserv = 1 if V083186a == 1
replace religserv = 2 if V083186a == 2
replace religserv = 3 if V083186a == 3
replace religserv = 4 if V083186a == 4
replace religserv = 5 if V083186a == 5
replace religserv = . if V083186a == -8
replace religserv = 5 if V083186 == 5
replace religserv = . if V083186 == -9
replace religserv = . if V083186 == -8

gen religpray = V083183
replace religpray = . if V083183 == 7
replace religpray = . if V083183 == -9
replace religpray = . if V083183 == -8 
 
gen religimp = V083181
replace religimp = . if V083181 == -9
replace religimp = . if V083181 == -8
replace religimp = 0 if V083181 == 5

gen	religfine	=	.				
replace	religfine	=	.	if	V083185x	==	-9
replace	religfine	=	.	if	V083185x	==	-8
replace	religfine	=	.	if	V083185x	==	-4
replace	religfine	=	.	if	V083185x	==	-1
replace	religfine	=	.	if	V083185x	==	0
replace	religfine	=	14	if	V083185x	==	10
replace	religfine	=	14	if	V083185x	==	20
replace	religfine	=	14	if	V083185x	==	30
replace	religfine	=	14	if	V083185x	==	40
replace	religfine	=	14	if	V083185x	==	99
replace	religfine	=	12	if	V083185x	==	100
replace	religfine	=	11	if	V083185x	==	110
replace	religfine	=	12	if	V083185x	==	120
replace	religfine	=	11	if	V083185x	==	121
replace	religfine	=	12	if	V083185x	==	123
replace	religfine	=	12	if	V083185x	==	124
replace	religfine	=	12	if	V083185x	==	125
replace	religfine	=	12	if	V083185x	==	126
replace	religfine	=	12	if	V083185x	==	127
replace	religfine	=	13	if	V083185x	==	129
replace	religfine	=	13	if	V083185x	==	130
replace	religfine	=	13	if	V083185x	==	131
replace	religfine	=	13	if	V083185x	==	132
replace	religfine	=	12	if	V083185x	==	133
replace	religfine	=	12	if	V083185x	==	135
replace	religfine	=	12	if	V083185x	==	147
replace	religfine	=	12	if	V083185x	==	148
replace	religfine	=	12	if	V083185x	==	149
replace	religfine	=	11	if	V083185x	==	150
replace	religfine	=	11	if	V083185x	==	160
replace	religfine	=	11	if	V083185x	==	161
replace	religfine	=	12	if	V083185x	==	162
replace	religfine	=	12	if	V083185x	==	164
replace	religfine	=	11	if	V083185x	==	165
replace	religfine	=	12	if	V083185x	==	167
replace	religfine	=	11	if	V083185x	==	168
replace	religfine	=	12	if	V083185x	==	169
replace	religfine	=	12	if	V083185x	==	180
replace	religfine	=	12	if	V083185x	==	181
replace	religfine	=	12	if	V083185x	==	182
replace	religfine	=	12	if	V083185x	==	183
replace	religfine	=	14	if	V083185x	==	184
replace	religfine	=	12	if	V083185x	==	185
replace	religfine	=	12	if	V083185x	==	186
replace	religfine	=	12	if	V083185x	==	199
replace	religfine	=	12	if	V083185x	==	200
replace	religfine	=	11	if	V083185x	==	220
replace	religfine	=	12	if	V083185x	==	221
replace	religfine	=	12	if	V083185x	==	222
replace	religfine	=	12	if	V083185x	==	224
replace	religfine	=	12	if	V083185x	==	225
replace	religfine	=	11	if	V083185x	==	229
replace	religfine	=	11	if	V083185x	==	230
replace	religfine	=	13	if	V083185x	==	231
replace	religfine	=	13	if	V083185x	==	232
replace	religfine	=	11	if	V083185x	==	233
replace	religfine	=	11	if	V083185x	==	239
replace	religfine	=	12	if	V083185x	==	240
replace	religfine	=	12	if	V083185x	==	242
replace	religfine	=	13	if	V083185x	==	243
replace	religfine	=	13	if	V083185x	==	244
replace	religfine	=	11	if	V083185x	==	249
replace	religfine	=	12	if	V083185x	==	250
replace	religfine	=	12	if	V083185x	==	251
replace	religfine	=	12	if	V083185x	==	253
replace	religfine	=	12	if	V083185x	==	254
replace	religfine	=	12	if	V083185x	==	255
replace	religfine	=	13	if	V083185x	==	256
replace	religfine	=	13	if	V083185x	==	257
replace	religfine	=	12	if	V083185x	==	258
replace	religfine	=	12	if	V083185x	==	260
replace	religfine	=	12	if	V083185x	==	261
replace	religfine	=	12	if	V083185x	==	264
replace	religfine	=	12	if	V083185x	==	267
replace	religfine	=	12	if	V083185x	==	268
replace	religfine	=	12	if	V083185x	==	269
replace	religfine	=	11	if	V083185x	==	270
replace	religfine	=	12	if	V083185x	==	271
replace	religfine	=	12	if	V083185x	==	272
replace	religfine	=	12	if	V083185x	==	275
replace	religfine	=	12	if	V083185x	==	276
replace	religfine	=	11	if	V083185x	==	279
replace	religfine	=	12	if	V083185x	==	280
replace	religfine	=	11	if	V083185x	==	281
replace	religfine	=	11	if	V083185x	==	282
replace	religfine	=	12	if	V083185x	==	289
replace	religfine	=	11	if	V083185x	==	290
replace	religfine	=	12	if	V083185x	==	291
replace	religfine	=	12	if	V083185x	==	292
replace	religfine	=	14	if	V083185x	==	300
replace	religfine	=	14	if	V083185x	==	301
replace	religfine	=	14	if	V083185x	==	302
replace	religfine	=	14	if	V083185x	==	303
replace	religfine	=	14	if	V083185x	==	304
replace	religfine	=	14	if	V083185x	==	305
replace	religfine	=	14	if	V083185x	==	306
replace	religfine	=	14	if	V083185x	==	308
replace	religfine	=	14	if	V083185x	==	309
replace	religfine	=	2	if	V083185x	==	400
replace	religfine	=	4	if	V083185x	==	500
replace	religfine	=	4	if	V083185x	==	501
replace	religfine	=	4	if	V083185x	==	502
replace	religfine	=	4	if	V083185x	==	503
replace	religfine	=	4	if	V083185x	==	524
replace	religfine	=	7	if	V083185x	==	600
replace	religfine	=	4	if	V083185x	==	650
replace	religfine	=	3	if	V083185x	==	700
replace	religfine	=	3	if	V083185x	==	701
replace	religfine	=	3	if	V083185x	==	702
replace	religfine	=	3	if	V083185x	==	705
replace	religfine	=	3	if	V083185x	==	706
replace	religfine	=	3	if	V083185x	==	708
replace	religfine	=	3	if	V083185x	==	719
replace	religfine	=	7	if	V083185x	==	720
replace	religfine	=	7	if	V083185x	==	721
replace	religfine	=	7	if	V083185x	==	722
replace	religfine	=	7	if	V083185x	==	723
replace	religfine	=	7	if	V083185x	==	724
replace	religfine	=	7	if	V083185x	==	725
replace	religfine	=	7	if	V083185x	==	726
replace	religfine	=	7	if	V083185x	==	729
replace	religfine	=	7	if	V083185x	==	730
replace	religfine	=	7	if	V083185x	==	732
replace	religfine	=	7	if	V083185x	==	740
replace	religfine	=	7	if	V083185x	==	790
replace	religfine	=	7	if	V083185x	==	795
replace	religfine	=	9	if	V083185x	==	880
replace	religfine	=	8	if	V083185x	==	881
replace	religfine	=	8	if	V083185x	==	882
replace	religfine	=	7	if	V083185x	==	997
replace	religfine	=	9	if	V083185x	==	888
replace	religfine	=	.	if	V083185x	==	889
replace	religfine	=	9	if	V083185x	==	890

keep year id preweight postweight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp religfine
order year id preweight postweight pastvote currentvote undecided issuevote haveopinion1 seediff1 haveopinion2 seediff2 haveopinion3 seediff3 haveopinion4 seediff4 haveopinion5 seediff5 religid religserv religpray religimp  religfine
saveold "Newmerge2008.dta", replace

 
*******************************************
** 2012
** At time of analysis, ANES had yet to add 2012 into cumulative, the following codes more variables to be included and consistent with cumulative

clear
use anes_timeseries_2012.dta
gen year=2012
gen weight = weight_full

gen pastvote = .
replace pastvote = 0 if interest_voted2008==2
replace pastvote = 1 if interest_whovote2008==1
replace pastvote = 2 if interest_whovote2008==2
replace pastvote = 3 if interest_whovote2008==5

gen currentvote = .
replace currentvote = 0 if presvote2012_x==-2
replace currentvote = 1 if presvote2012_x==1
replace currentvote = 2 if presvote2012_x==2
replace currentvote = 3 if presvote2012_x==5

gen pidstrength = 0 if pid_x==4
replace pidstrength = 1 if pid_x==3
replace pidstrength = 1 if pid_x==5
replace pidstrength = 1 if pid_x==2
replace pidstrength = 1 if pid_x==6
replace pidstrength = 2 if pid_x==1
replace pidstrength = 2 if pid_x==7
tab pidstrength pid_x

gen partydiff = 0 if ptydiff_diff==2
replace partydiff = 0 if ptydiff_diff==-8
replace partydiff = 1 if ptydiff_diff==1
mean partydiff [iw=weight], over(pidstrength)

gen polsoph = iwrobspre_levinfo
replace polsoph = . if iwrobspre_levinfo<0

gen levinfo = 0 if iwrobspre_levinfo>0
replace levinfo = 1 if iwrobspre_levinfo==1
replace levinfo = 1 if iwrobspre_levinfo==2

gen undecided = 0 if prevote_intpres==1 
replace undecided = 1 if prevote_intpreswho==-8
replace undecided = . if prevote_intpreswho==-9
*replace undecided = 1 if regexm(prevote_intpreswho_othtxt,"[Kk][Nn][Oo][Ww]")
*replace undecided = 1 if regexm(prevote_intpreswho_othtxt,"decide")
*replace undecided = 1 if regexm(prevote_intpreswho_othtxt,"deside")
*replace undecided = 1 if regexm(prevote_intpreswho_othtxt,"[Ss][Uu][Rr][Ee]")
*replace undecided = 1 if regexm(prevote_intpreswho_othtxt,"[Nn]one")
*replace undecided = 1 if regexm(prevote_intpreswho_othtxt,"kown")

* gov insurance 7.8
gen haveopinion1= 0 if inspre_self>-9 & inspre_self!=.
replace haveopinion1 = 1 if inspre_self>=1 & inspre_self<=7
gen seediff1= 0 if haveopinion1==0
replace seediff1 = 0 if inspre_dpc ==-8
replace seediff1 = 0 if inspre_rpc ==-8
replace seediff1 = . if inspre_dpc ==-9
replace seediff1 = . if inspre_rpc ==-9
replace seediff1 = 0 if inspre_dpc==inspre_rpc & inspre_dpc>=1 & inspre_dpc<=7  & inspre_rpc>=1 & inspre_rpc<=7
replace seediff1 = 1 if inspre_dpc!=inspre_rpc & inspre_dpc>=1 & inspre_dpc<=7  & inspre_rpc>=1 & inspre_rpc<=7 

* standard of living, 7.4
gen haveopinion2= 0 if guarpr_self>-9 & guarpr_self!=.
replace haveopinion2 = 1 if guarpr_self>=1 & guarpr_self<=7
gen seediff2= 0 if haveopinion2==0
replace seediff2 = 0 if guarpr_dpc ==-8
replace seediff2 = 0 if guarpr_rpc ==-8
replace seediff2 = . if guarpr_dpc ==-9
replace seediff2 = . if guarpr_rpc ==-9
replace seediff2 = 0 if guarpr_dpc==guarpr_rpc & guarpr_dpc>=1 & guarpr_dpc<=7  & guarpr_rpc>=1 & guarpr_rpc<=7
replace seediff2 = 1 if guarpr_dpc!=guarpr_rpc & guarpr_dpc>=1 & guarpr_dpc<=7  & guarpr_rpc>=1 & guarpr_rpc<=7 

* spsrvpr_ssself Gov services, 11.4 DK/have not
gen haveopinion3= 0 if spsrvpr_ssself>-9 & spsrvpr_ssself!=.
replace haveopinion3 = 1 if spsrvpr_ssself>=1 & spsrvpr_ssself<=7
gen seediff3= 0 if haveopinion3==0
replace seediff3 = 0 if spsrvpr_ssdpc ==-8
replace seediff3 = 0 if spsrvpr_ssrpc ==-8
replace seediff3 = . if spsrvpr_ssdpc ==-9
replace seediff3 = . if spsrvpr_ssrpc ==-9
replace seediff3 = 0 if spsrvpr_ssdpc==spsrvpr_ssrpc & spsrvpr_ssdpc>=1 & spsrvpr_ssdpc<=7  & spsrvpr_ssrpc>=1 & spsrvpr_ssrpc<=7
replace seediff3 = 1 if spsrvpr_ssdpc!=spsrvpr_ssrpc & spsrvpr_ssdpc>=1 & spsrvpr_ssdpc<=7  & spsrvpr_ssrpc>=1 & spsrvpr_ssrpc<=7 

* defsppr_self 12.2
gen haveopinion4= 0 if defsppr_self>-9 & defsppr_self!=.
replace haveopinion4 = 1 if defsppr_self>=1 & defsppr_self<=7
gen seediff4= 0 if haveopinion4==0
replace seediff4 = 0 if defsppr_dpc ==-8
replace seediff4 = 0 if defsppr_rpc ==-8
replace seediff4 = . if defsppr_dpc ==-9
replace seediff4 = . if defsppr_rpc ==-9
replace seediff4 = 0 if defsppr_dpc==defsppr_rpc & defsppr_dpc>=1 & defsppr_dpc<=7  & defsppr_rpc>=1 & defsppr_rpc<=7
replace seediff4 = 1 if defsppr_dpc!=defsppr_rpc & defsppr_dpc>=1 & defsppr_dpc<=7  & defsppr_rpc>=1 & defsppr_rpc<=7 

* aid to blacks, 12.5
gen haveopinion5= 0 if aidblack_self>-9 & aidblack_self!=.
replace haveopinion5 = 1 if aidblack_self>=1 & aidblack_self<=7
gen seediff5= 0 if haveopinion5==0
replace seediff5 = 0 if aidblack_dpc ==-8
replace seediff5 = 0 if aidblack_rpc ==-8
replace seediff5 = . if aidblack_dpc ==-9
replace seediff5 = . if aidblack_rpc ==-9
replace seediff5 = 0 if aidblack_dpc==aidblack_rpc & aidblack_dpc>=1 & aidblack_dpc<=7  & aidblack_rpc>=1 & aidblack_rpc<=7
replace seediff5 = 1 if aidblack_dpc!=aidblack_rpc & aidblack_dpc>=1 & aidblack_dpc<=7  & aidblack_rpc>=1 & aidblack_rpc<=7 

gen issuevote1 = 0 if haveopinion1+seediff1!=2
replace issuevote1 = 1 if haveopinion1+seediff1==2
replace issuevote1 = . if haveopinion1==.
gen issuevote2 = 0 if haveopinion2+seediff2!=2
replace issuevote2 = 1 if haveopinion2+seediff2==2
replace issuevote2 = . if haveopinion2==.
gen issuevote3 = 0 if haveopinion3+seediff3!=2
replace issuevote3 = 1 if haveopinion3+seediff3==2
replace issuevote3 = . if haveopinion3==.    
gen issuevote4 = 0 if haveopinion4+seediff4!=2
replace issuevote4 = 1 if haveopinion4+seediff4==2
replace issuevote4 = . if haveopinion4==.
gen issuevote5 = 0 if haveopinion5+seediff5!=2
replace issuevote5 = 1 if haveopinion5+seediff5==2
replace issuevote5 = . if haveopinion5==.

gen issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4 + issuevote5)/5
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote4)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote3 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote2 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote1+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.
replace issuevote = (issuevote2+issuevote3 +issuevote4 + issuevote5)/4 if issuevote==.

gen importantdiffs= ptydiff_diff
recode importantdiffs 2=0 -6=. -7=. -8=0 -9=.

set type double
gen id = caseid+20120000

* exact age not given, replace age category with mean age of group
gen age = 19 if dem_agegrp==1
replace age = 22.5 if dem_agegrp==2
replace age = 27 if dem_agegrp==3
replace age = 32 if dem_agegrp==4
replace age = 37 if dem_agegrp==5
replace age = 42 if dem_agegrp==6
replace age = 47 if dem_agegrp==7
replace age = 52 if dem_agegrp==8
replace age = 57 if dem_agegrp==9
replace age = 62 if dem_agegrp==10
replace age = 67 if dem_agegrp==11
replace age = 72 if dem_agegrp==12
replace age = 77 if dem_agegrp==13

gen education = dem_edugroup
recode education 1=0 2=1 3=2 4/5=3 -2=. -9=.

gen black = 0 if dem_raceeth>0 & dem_raceeth!=.
replace black = 1 if dem_raceeth==2

gen female = 0
replace female = 1 if gender_respondent==2

gen religid = .
replace religid = . if relig_7cat_x == -2
replace religid = 1 if relig_7cat_x >= 1 & relig_7cat_x <= 3 
replace religid = 1 if relig_7cat_x == 5
replace religid = 2 if relig_7cat_x == 4
replace religid = 4 if relig_7cat_x == 6
replace religid = 7 if relig_7cat_x == 7
replace religid = 9 if relig_7cat_x == 8

gen	religfine	=	.				
replace	religfine	=	.	if	relig_mastersummary	==	-9
replace	religfine	=	.	if	relig_mastersummary	==	-8
replace	religfine	=	.	if	relig_mastersummary	==	-4
replace	religfine	=	.	if	relig_mastersummary	==	-2
replace	religfine	=	.	if	relig_mastersummary	==	-1
replace	religfine	=	.	if	relig_mastersummary	==	0
replace	religfine	=	14	if	relig_mastersummary	==	10
replace	religfine	=	14	if	relig_mastersummary	==	20
replace	religfine	=	14	if	relig_mastersummary	==	30
replace	religfine	=	14	if	relig_mastersummary	==	40
replace	religfine	=	14	if	relig_mastersummary	==	99
replace	religfine	=	12	if	relig_mastersummary	==	100
replace	religfine	=	11	if	relig_mastersummary	==	110
replace	religfine	=	12	if	relig_mastersummary	==	120
replace	religfine	=	11	if	relig_mastersummary	==	121
replace	religfine	=	12	if	relig_mastersummary	==	123
replace	religfine	=	12	if	relig_mastersummary	==	124
replace	religfine	=	12	if	relig_mastersummary	==	125
replace	religfine	=	12	if	relig_mastersummary	==	126
replace	religfine	=	12	if	relig_mastersummary	==	127
replace	religfine	=	12	if	relig_mastersummary	==	128
replace	religfine	=	13	if	relig_mastersummary	==	129
replace	religfine	=	13	if	relig_mastersummary	==	130
replace	religfine	=	13	if	relig_mastersummary	==	131
replace	religfine	=	13	if	relig_mastersummary	==	132
replace	religfine	=	12	if	relig_mastersummary	==	133
replace	religfine	=	12	if	relig_mastersummary	==	135
replace	religfine	=	12	if	relig_mastersummary	==	147
replace	religfine	=	12	if	relig_mastersummary	==	148
replace	religfine	=	12	if	relig_mastersummary	==	149
replace	religfine	=	11	if	relig_mastersummary	==	150
replace	religfine	=	11	if	relig_mastersummary	==	160
replace	religfine	=	11	if	relig_mastersummary	==	161
replace	religfine	=	12	if	relig_mastersummary	==	162
replace	religfine	=	12	if	relig_mastersummary	==	164
replace	religfine	=	11	if	relig_mastersummary	==	165
replace	religfine	=	12	if	relig_mastersummary	==	166
replace	religfine	=	12	if	relig_mastersummary	==	167
replace	religfine	=	11	if	relig_mastersummary	==	168
replace	religfine	=	12	if	relig_mastersummary	==	169
replace	religfine	=	12	if	relig_mastersummary	==	180
replace	religfine	=	12	if	relig_mastersummary	==	181
replace	religfine	=	12	if	relig_mastersummary	==	182
replace	religfine	=	12	if	relig_mastersummary	==	183
replace	religfine	=	14	if	relig_mastersummary	==	184
replace	religfine	=	12	if	relig_mastersummary	==	185
replace	religfine	=	12	if	relig_mastersummary	==	186
replace	religfine	=	12	if	relig_mastersummary	==	199
replace	religfine	=	12	if	relig_mastersummary	==	200
replace	religfine	=	11	if	relig_mastersummary	==	220
replace	religfine	=	12	if	relig_mastersummary	==	221
replace	religfine	=	12	if	relig_mastersummary	==	222
replace	religfine	=	12	if	relig_mastersummary	==	224
replace	religfine	=	12	if	relig_mastersummary	==	225
replace	religfine	=	11	if	relig_mastersummary	==	229
replace	religfine	=	11	if	relig_mastersummary	==	230
replace	religfine	=	13	if	relig_mastersummary	==	231
replace	religfine	=	13	if	relig_mastersummary	==	232
replace	religfine	=	11	if	relig_mastersummary	==	233
replace	religfine	=	11	if	relig_mastersummary	==	239
replace	religfine	=	12	if	relig_mastersummary	==	240
replace	religfine	=	12	if	relig_mastersummary	==	242
replace	religfine	=	13	if	relig_mastersummary	==	243
replace	religfine	=	13	if	relig_mastersummary	==	244
replace	religfine	=	11	if	relig_mastersummary	==	249
replace	religfine	=	12	if	relig_mastersummary	==	250
replace	religfine	=	12	if	relig_mastersummary	==	251
replace	religfine	=	12	if	relig_mastersummary	==	253
replace	religfine	=	12	if	relig_mastersummary	==	254
replace	religfine	=	12	if	relig_mastersummary	==	255
replace	religfine	=	13	if	relig_mastersummary	==	256
replace	religfine	=	13	if	relig_mastersummary	==	257
replace	religfine	=	12	if	relig_mastersummary	==	258
replace	religfine	=	12	if	relig_mastersummary	==	260
replace	religfine	=	12	if	relig_mastersummary	==	261
replace	religfine	=	12	if	relig_mastersummary	==	262
replace	religfine	=	12	if	relig_mastersummary	==	264
replace	religfine	=	12	if	relig_mastersummary	==	267
replace	religfine	=	12	if	relig_mastersummary	==	268
replace	religfine	=	12	if	relig_mastersummary	==	269
replace	religfine	=	11	if	relig_mastersummary	==	270
replace	religfine	=	12	if	relig_mastersummary	==	271
replace	religfine	=	12	if	relig_mastersummary	==	272
replace	religfine	=	12	if	relig_mastersummary	==	275
replace	religfine	=	12	if	relig_mastersummary	==	276
replace	religfine	=	11	if	relig_mastersummary	==	279
replace	religfine	=	12	if	relig_mastersummary	==	280
replace	religfine	=	11	if	relig_mastersummary	==	281
replace	religfine	=	11	if	relig_mastersummary	==	282
replace	religfine	=	12	if	relig_mastersummary	==	289
replace	religfine	=	11	if	relig_mastersummary	==	290
replace	religfine	=	12	if	relig_mastersummary	==	291
replace	religfine	=	12	if	relig_mastersummary	==	292
replace	religfine	=	14	if	relig_mastersummary	==	300
replace	religfine	=	14	if	relig_mastersummary	==	301
replace	religfine	=	14	if	relig_mastersummary	==	302
replace	religfine	=	14	if	relig_mastersummary	==	303
replace	religfine	=	14	if	relig_mastersummary	==	304
replace	religfine	=	14	if	relig_mastersummary	==	305
replace	religfine	=	14	if	relig_mastersummary	==	306
replace	religfine	=	14	if	relig_mastersummary	==	308
replace	religfine	=	14	if	relig_mastersummary	==	309
replace	religfine	=	2	if	relig_mastersummary	==	400
replace	religfine	=	4	if	relig_mastersummary	==	500
replace	religfine	=	4	if	relig_mastersummary	==	501
replace	religfine	=	4	if	relig_mastersummary	==	502
replace	religfine	=	4	if	relig_mastersummary	==	503
replace	religfine	=	4	if	relig_mastersummary	==	524
replace	religfine	=	7	if	relig_mastersummary	==	600
replace	religfine	=	4	if	relig_mastersummary	==	650
replace	religfine	=	7	if	relig_mastersummary	==	695
replace	religfine	=	3	if	relig_mastersummary	==	700
replace	religfine	=	3	if	relig_mastersummary	==	701
replace	religfine	=	3	if	relig_mastersummary	==	702
replace	religfine	=	3	if	relig_mastersummary	==	705
replace	religfine	=	3	if	relig_mastersummary	==	706
replace	religfine	=	3	if	relig_mastersummary	==	708
replace	religfine	=	3	if	relig_mastersummary	==	719
replace	religfine	=	7	if	relig_mastersummary	==	720
replace	religfine	=	7	if	relig_mastersummary	==	721
replace	religfine	=	7	if	relig_mastersummary	==	722
replace	religfine	=	7	if	relig_mastersummary	==	723
replace	religfine	=	7	if	relig_mastersummary	==	724
replace	religfine	=	7	if	relig_mastersummary	==	725
replace	religfine	=	7	if	relig_mastersummary	==	726
replace	religfine	=	7	if	relig_mastersummary	==	729
replace	religfine	=	7	if	relig_mastersummary	==	730
replace	religfine	=	7	if	relig_mastersummary	==	732
replace	religfine	=	7	if	relig_mastersummary	==	740
replace	religfine	=	7	if	relig_mastersummary	==	790
replace	religfine	=	7	if	relig_mastersummary	==	795
replace	religfine	=	7	if	relig_mastersummary	==	870
replace	religfine	=	7	if	relig_mastersummary	==	879
replace	religfine	=	9	if	relig_mastersummary	==	880
replace	religfine	=	8	if	relig_mastersummary	==	881
replace	religfine	=	8	if	relig_mastersummary	==	882
replace	religfine	=	7	if	relig_mastersummary	==	997
replace	religfine	=	9	if	relig_mastersummary	==	888
replace	religfine	=	.	if	relig_mastersummary	==	889
replace	religfine	=	9	if	relig_mastersummary	==	890

gen religserv = .
replace religserv = 1 if relig_churchoft == 1
replace religserv = 2 if relig_churchoft == 2
replace religserv = 3 if relig_churchoft == 3
replace religserv = 4 if relig_churchoft == 4
replace religserv = 5 if relig_churchoft == 5
replace religserv = . if relig_churchoft == -9
replace religserv = 5 if relig_church == 2
replace religserv = . if relig_church == -9
replace religserv = . if relig_church == -8

gen religpray = .
replace religpray = . if relig_pray == -9
replace religpray = . if relig_pray == -8
replace religpray = 1 if relig_pray == 01
replace religpray = 2 if relig_pray == 02
replace religpray = 3 if relig_pray == 03
replace religpray = 4 if relig_pray == 04
replace religpray = 5 if relig_pray == 05
replace religpray = . if relig_pray == 95

gen religimp = .
replace religimp = relig_import
replace religimp = . if relig_import == -9
replace religimp = . if relig_import == -8
replace religimp = 0 if relig_import == 2

keep year id weight weight_ftf age female black education pidstrength polsoph pastvote currentvote undecided issuevote importantdiffs religid religserv religpray religimp religfine
order year id weight pastvote currentvote undecided issuevote religid religserv religpray religimp religfine
saveold "Newmerge2012.dta", replace

